Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Comparing function objects

Reply
Thread Tools

Comparing function objects

 
 
rush.william@gmail.com
Guest
Posts: n/a
 
      02-16-2007
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.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      02-19-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Comparing objects to built-in literals Richard Hayden Python 1 03-11-2005 09:31 PM
Comparing two minidom objects Skip Montanaro Python 5 11-13-2004 10:22 PM
Comparing Array Objects Raphael Iloh ASP .Net 1 02-22-2004 05:00 PM
Comparing objects - is there a maximum object? Chris Brew Python 5 09-06-2003 01:48 AM



Advertisments