title: Assigning a function pointer with variable arguments using parameter pack
body: <p>I would like to store as a member variable a pointer to a function that may take a variable number of arguments of different types.</p>
  
  <p>The basic construct I've been trying to use is along these lines</p>
  
  <pre><code>template &lt;typename... Args&gt;
  using ArgsFuncPointer = void(*)(Args...);
  
  template&lt;typename... Args&gt; void varArgsFunc(Args&amp;&amp;... args) {  }
  
  {
      ArgsFuncPointer&lt;int, float&gt; funcPointer = varArgsFunc;   
      funcPointer(1, 2.0);
  }
  </code></pre>
  
  <p>The problem is that <code>varArgsFunc</code> cannot be converted to <code>ArgsFuncPointer&lt;int, float&gt;</code></p>
  
  <p>See <a href="http://coliru.stacked-crooked.com/a/b73aab6db68c8174" rel="nofollow noreferrer">coliru</a> for a (non-)working example.</p>
  
  <p>Ultimately I would like to be able to do something like:</p>
  
  <pre><code>template &lt;typename... Args&gt; class Foo
  {
  public:
      Foo(Args&amp;&amp;... args)
      {
          func(args);
      }
  
      VarArgsFuncPointer func;
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>It turns out the reason this wouldn't compile is due to the subtle difference in signature between <code>ArgsFuncPointer</code> and <code>varArgsFunc</code>. With <code>ArgsFuncPointer</code> the parameter pack is passed by rvalue reference, whereas with <code>varArgsFunc</code> the parameter pack is passed by value. </p>
  
  <p>This works:</p>
  
  <pre><code>template &lt;typename... Args&gt;
  using ArgsFuncPointer = void(*)(Args&amp;&amp;...);
  
  template&lt;typename... Args&gt; void varArgsFunc(Args&amp;&amp;... args) {  }
  
  {
      ArgsFuncPointer&lt;int, float&gt; funcPointer = varArgsFunc;   
      funcPointer(1, 2.0);
  }
  </code></pre>
  
  <p>Working example <a href="http://coliru.stacked-crooked.com/a/5e585f1ca7aeacb0" rel="nofollow noreferrer">here</a></p>