Comparing function objects

Discussion in 'C++' started by rush.william@gmail.com, Feb 16, 2007.

  1. Guest

    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.
     
    , Feb 16, 2007
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Feb 19, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raphael Iloh

    Comparing Array Objects

    Raphael Iloh, Feb 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    382
    Alvin Bruney [MVP]
    Feb 22, 2004
  2. Chris Brew
    Replies:
    5
    Views:
    288
    Andrew Dalke
    Sep 6, 2003
  3. Skip Montanaro

    Comparing two minidom objects

    Skip Montanaro, Nov 8, 2004, in forum: Python
    Replies:
    5
    Views:
    419
    Christos TZOTZIOY Georgiou
    Nov 13, 2004
  4. Richard Hayden

    Comparing objects to built-in literals

    Richard Hayden, Mar 11, 2005, in forum: Python
    Replies:
    1
    Views:
    302
  5. 7stud
    Replies:
    11
    Views:
    725
    Dennis Lee Bieber
    Mar 20, 2007
Loading...

Share This Page