There is a way, with the use of boost::function::target()
template method. But since boost::bind
return unspecified type, witch do not yet provide a way to access arguments, you will need to write your own binder functor. Here is some example:
class MyClass
{
public:
void myMethod()
{
std::cout << "This is my Method" << std::endl;
}
};
struct MyFunctor
{
MyFunctor(MyClass* o, void (MyClass::*m)()): object(o),method(m){}
MyClass* object;
void (MyClass::*method)();
void operator() ()
{
return (object->*method)();
}
};
So now you can access:
MyClass myObject;
boost::function< void() > func= MyFunctor(&myObject, &MyClass::myMethod);
func();
assert( func.target<MyFunctor>()->object == &myObject );
Same as with the boost::any
there is no way to have polymorphic access witch the target
template method.