Comparing boost bind object with a pointer to member function

Hello, Is is possible to compare a pointer to member function with a function object returned by boost bind? I have a class with several different functions; for each member function I use boost bind to bind the function object to several args. At the point where I want call the function object, I would like to check which member function it's been bound to, and decide whether or no it should be executed. For example, I would like the second comparison in the code snippet below to return "Bind match." For any other member function of foo it should return "Bind not match." Thanks. int main(int, char**) { Data d(1, 2); Foo fx, fy; //typedef void (Foo::*foofunctwo_t)(const Data&); //foofunctwo_t del1 = &Foo::FuncTwo; boost::function<void (Foo*, const Data&)> bf(&Foo::FuncTwo); if(bf == &Foo::FuncTwo) { cout << "match" <<endl; } else { cout << "no match" << endl; } boost::function<void (const Data&)> boundfunc = boost::bind(&Foo::FuncTwo, &fx, _1); if(boundfunc == &Foo::FuncTwo) { cout << "Bind match" << endl; } else { cout << "Bind not match" << endl; } return 0; }; -- View this message in context: http://old.nabble.com/Comparing-boost-bind-object-with-a-pointer-to-member-f... Sent from the Boost - Users mailing list archive at Nabble.com.

"jej" wrote: ...
boost::function<void (const Data&)> boundfunc = boost::bind(&Foo::FuncTwo, &fx, _1); if(boundfunc == &Foo::FuncTwo)
If you compare boundfunc to its actual value: if( boundfunc == boost::bind(&Foo::FuncTwo, &fx, _1) ) does it not work?

Yes, that does work, but actually is not quite what I want to do. I made a mistake in the original example. In the corrected example, what I really want is for the second case to return "bound match," which it doesn't do. The line above the comparison doesn't compile, and even so, is not quite what I would like either. That is, I want to know which member function the func object is bound to, and don't really care about the values of the arguments (which I don't know). Thanks! int main(int, char**) { Data d(1, 2); Foo fx, fy; boost::function<void (Foo*, const Data&)> bf(&Foo::FuncTwo); if(bf == &Foo::FuncTwo) { cout << "match" <<endl; } else { cout << "no match" << endl; } boost::function<void (Foo*)> func = boost::bind(&Foo::FuncTwo, _1, d); //if(func == boost::bind(&Foo::FuncTwo, _1, d)) //doesn't compile if(func == &Foo::FuncTwo) { cout << "bound match" << endl; } else { cout << "no bound match" << endl; } return 0; } -- View this message in context: http://old.nabble.com/Comparing-boost-bind-object-with-a-pointer-to-member-f... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
jej
-
Peter Dimov