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 some
Lose the typedef. A function that takes variable arguments is a specific type, it's not compatible with functions taking typed arguments, and it can't have parameter types specified later.
This should work instead:
template Foo(function f);
Of course, what you really need is to template the class, so you can remember what arguments the function requires.
#include
template
class Foo
{
std::function m_f;
public:
Foo( std::function f ) : m_f(f) {}
void operator()(ARGS... args) const { m_f(args...); }
};
template
Foo MakeFoo(void(*f)(ARGS...)) { return Foo(f); }
void func1(double *a1, double *a2, double *b)
{ //do something
}
int main(void)
{
auto func1_functor = MakeFoo(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;
}
Demo: http://ideone.com/fnUg2