how do we pass an arbitrary function to another function
<p>I have a question continuing the post <a href="http://stackoverflow.com/questions/1174169/function-passed-as-template-argument">function passed as template argument</a>. In the provided code:</p>

<pre><code>#include &lt;iostream&gt;

void add1(int &amp;v)
{
  v+=1;
}

void add2(int &amp;v)
{
  v+=2;
}

template &lt;void (*T)(int &amp;)&gt;
void doOperation()
{
  int temp=0;
  T(temp);
  std::cout &lt;&lt; "Result is " &lt;&lt; temp &lt;&lt; std::endl;
}

int main()
{
  doOperation&lt;add1&gt;();
  doOperation&lt;add2&gt;();
}
</code></pre>

<p>what about a third function which has a different parameter set layout, e.g.</p>

<pre><code>double add3(double v1, double v2)
{
return v1+v2;
}
</code></pre>

<p>If this is not achievable using template at all, how do we pass an arbitrary function to another function? And how do we handle the parameter set with all kinds of possibilities? I know python may be able to do it by passing a tuple (kwargs**), but not sure about C/C++.</p>
