title: c++ passing variable number of arguments to a function
body: <p>I have functions that take a different number of arguments (one or more double values). Pointers to these functions are stored in a vector within a formula-interpreter and will be used to call functions at runtime when needed. The function to call and the number of arguments to pass depends on the formula itself and will be known only at runtime.</p>
  
  <p>From interpreting the formula I get an iterator pointing to the function to call and a <code>vector&lt;double&gt;</code> with the arguments to pass. In the current version I solve the need to pass variable number of arguments by code duplication like :</p>
  
  <pre><code>// (the number of args in dblVec to match the number of args the function accepts is checked previously)
  if (dblVec.size() == 1) result = (*funcIter)-&gt;function(dblVec.at(0)); 
  else if (dblVec.size() == 2) result = (*funcIter)-&gt;function(dblVec.at(0), dblVec.at(1)); 
  else if (dblVec.size() == 3) result = (*funcIter)-&gt;function(dblVec.at(0), dblVec.at(1), dblVec.at(2)); 
  ...
  </code></pre>
  
  <p>This is not very elegant and has a limit but it works if the number of arguments is not larger than the number of above tests. My question is:</p>
  
  <p>Is there some way to have an "implicit" loop within the argument list for a function to call, like (pseudo code)</p>
  
  <pre><code>result = (*funcIter)-&gt;function(passVectorContentsAsMultipleSeparatedDoubles(dblVec));
  </code></pre>
  
  <p>It is not a solution to pass the whole vector because the functions will be "standard" functions (like <code>sin(double)</code>, <code>cos(double)</code>, <code>atan2(double, double)</code> etc.) as well as custom functions passed to the interpreting class by the user (programmer that uses the interpreting class).</p>
  
  <p>Thanks in advance for any hints.</p>