title: Variadic Function for Kronecker Product
body: <p>I'm having trouble constructing a variadic function that does a particular task. For my particular example I'm using 2x2 matrices but you could imagine that my issue generalises to many data types. Also, for my example, "eye" is the 2x2 identity matrix.</p>
  
  <p>Ok, so I would like to construct a variadic function f whose inputs might be (to give 3 examples):</p>
  
  <pre><code>f(Y, 2, Z, 5, X, 3)
  f(X, 4)
  f(X, 2, Y, 1)
  </code></pre>
  
  <p>where X, Y, Z are matrices, and the numbers are positive ints. It should return the following pseudo-code kronecker products, respectively: </p>
  
  <pre><code>KroneckerProduct(eye, Y, X, eye, Z)
  
  KroneckerProduct(eye, eye, eye, X)
  
  KroneckerProduct(Y, X)
  </code></pre>
  
  <p>So essentially it applies a matrix at the position in the KroneckerProduct specified by the int that follows the matrix, and fills in identity matrices in between.</p>
  
  <p>Due to my inexperience with variadic functions, I haven't gotten far with it. My biggest problem is getting 'recursive' step of the variadic function to do what I need (see comments at end):</p>
  
  <pre><code>template&lt;typename M, typename I, typename... Args&gt;
  arma::mat f(M matrix, I position, Args... args) 
  {
      std::vector&lt;arma::mat&gt; matrixList;
  
      while(position &gt; matrixList.size()) 
      {
          matrixList.push_back(eye&lt;arma::mat&gt;(2,2));
      }
  
      matrixList(position-1) = matrix;
  
      //Up until here, it's satisfied the first pair of arguments.
      //However, if I call f(args...) now, it'll just re-initialize matrixList
  }
  </code></pre>
  
  <p>Is there a workaround that I'm missing?</p>