I’ve wrote a functor library (based on the tutorial at: http://www.tutok.sk/fastgl/callback.html).
Currently, I can write the following code:
class MyClass
{
public:
void Test(int a,int b);
};
MyClass c;
Functor2<void,int,int> f=makeFunctor(c,&MyClass::Test);
...
f(1,2);
I would like to add another feature so I can bind parameters with the actual function (to pass it forward), so for example:
Functor0<void> f=makeFunctor(c,&MyClass::Test,3,4);
...
f(); // this will use the default parameters 3,4
I know that boost has that functionality, but I don’t want to use that – I would like to write it myself.
My question is how to define a functor where I can also pass default arguments to be used in the call itself. The reason I don’t want to use boost nor std++ is because this code is cross platform and will be used on some platforms which do not have boost.
If you really don’t want (or can’t) use the work of other people who have already solved this problem, how about a constructor for the functor to keep the parameters you want to pass?!?
You’d have to tidy this up (eg. to include the return type of the BinaryFunctor in the template args, and btw I’ve not compiled it!) but something like this should work