title: Generic functor for functions with any argument list
body: <p>I need to implement a functor that takes any (!) function pointer when instantiated, analyses the argument types, stores the pointer and when operator() is called, does something with the pointer. The easiest case being, calling the function with its arguments.</p>
  
  <p>I tried converting the function pointer to something like std::function and I get the error:</p>
  
  <pre><code>error: invalid use of incomplete type ‘struct std::function&lt;void (*)(...)&gt;’
  /usr/include/c++/4.6/functional:1572:11: error: declaration of ‘struct std::function&lt;void(*)(...)&gt;’
  </code></pre>
  
  <p>I am using gcc 4.6.1, compiling with -std=c++0x</p>
  
  <p>This is a minimal example:</p>
  
  <pre><code>#include &lt;functional&gt;
  
  using namespace std;
  typedef void (*F_vararg)(...);
  class Foo
  {
      public:
          template&lt;typename... ARGS&gt; Foo(function&lt;F_vararg(ARGS... args)&gt; f);
          ~Foo(){}
          template&lt;typename... ARGS&gt;void operator()(ARGS... args);
      private:
          F_vararg m_f;
  };
  
  template&lt;typename... ARGS&gt; 
  Foo::Foo(function&lt;F_vararg(ARGS... args)&gt; f)
  {
      m_f = f;
  }
  
  template&lt;typename... ARGS&gt;
  void Foo::operator()(ARGS... args)
  {
      m_f(args...);
  }
  
  void func1(double *a1, double *a2, double *b)
  {    //do something 
  }
  
  int main(void)
  {
      Foo func1_functor((std::function&lt;void (*)(...)&gt;)(func1));
  
      double a1[3] = {2.,3.,4.};
      double a2[3] = {2.2,3.2,4.2};
      double b[3] = {1.5,2.5,3.5};
  
      func1_functor(a1,a2,b);
  
      return 0;
  }
  </code></pre>
  
  <p>This does NOT compile... If I don't declare the constructor as a template but with     "F_vararg f" as the argument, and adjust the cast in the instantiation accordingly, it works (should it?) but I have no chance (?) of getting any information on the arguments of func1 in the constructor of the functor which I need.</p>
  
  <p>Am I missing something? Is there another way to do that? </p>
  
  <p>Thank you in advance !!! </p>
  
  <p>cheers, Steffen</p>
  
  <p><strong>edit</strong>
  Wow, that was quick! I need that for postponing the execution of functions. The functor (or another class) should be able to decide whether and when to run a function. To decide that it will use the information gathered from the argument list.</p>
  
  <p>I have looked at std::bind but I couldn't think of a way to achieve what I want...</p>