I’ve been lurking here, trying to figure out if a Functor can do what I need it to do.
What I would like to do is wrap a call to a class method and somehow capture the value that the function returns. Given my Functor class, what will I need to do to turn my comments into code:
template < typename Func >
class MySpecializedFunctor
{
Func t;
MyObject& p;
public:
MyFunctor( MyObject &obj, Func f )
{
p = obj;
t = f;
}
void runFunc( ... )
{
// Can I use an ellipsis '...' to pass values into t->xxxx() ???
// Assume the first param is always time, the others are never the same
bool b = p->t( time( NULL ), /* first value of ... */, /* second value of ... */ );
if ( !b )
{
// log error here
}
}
}
Because this is a Functor of sorts, the function being wrapped could have n number of parameters.
Is this possible?
EDIT: I cannot use C++0X.
Use variadic templates:
Or overload runFunc, if your compiler has no support for variadic templates or perfect forwarding: