Comparing function objects

R

rush.william

Hi All!

Is there any way to compare 2 boost::function<> objects?
boost::function has no operator==() for comparing boost::function<>.
Is there any hack way? I need to do the following:

struct A
{
void f(int) {};
};

struct B
{
void f(int) {};
};

int main()
{
A a;
B b;

boost::function< void (int) > f1(boost::bind(&A::f, &a, _1));
boost::function< void (int) > f2(boost::bind(&B::f, &b, _1));
boost::function< void (int) > f3(boost::bind(&B::f, &b, _1));

// This works well:
std::cout<< ((f2 == boost::bind(&B::f, &b, _1)) ? "equal" : "not
equal" )<<std::endl;

// This doesn't compile...
std::cout<< ((f1 == f2) ? "equal" : "not equal" )<<std::endl;
};

Any ideas?

WBR, Sectoid.
 
V

Victor Bazarov

Is there any way to compare 2 boost::function<> objects?

Just to let you know, www.boost.org has online discussion forums,
where you should be able to ask about any Boost feature.
boost::function has no operator==() for comparing boost::function<>.
Is there any hack way?

Why should there be a "hack way". Just define your own operator.
The equality operator doesn't have to be a member, so defined it
as non-member and be done.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top