7
void ff(int){} 

void Unscribe(const boost::function<void(int)>& f)
{
    std::map<int, boost::function<void(int)> > map;

    map[0] = ff;

    if( map[0] == f)
    {

    }  
}

Unscribe( ff ); 

I would like to be able to compare two boost::function with the same signature. What should I modified to get this code compilable ?

Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145

2 Answers2

14

You can't. Read the boost function FAQ's first entry:

  1. Why can't I compare boost::function objects with operator== or operator!=?

Comparison between boost::function objects cannot be implemented "well", and therefore will not be implemented. ...

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
-1

Are you looking to compare signatures, or functor equality (that two functors point to the same underlying memory address)? If its the latter, you can use the interface provided by boost/function_equal.hpp:

Boost Function Equal

template<typename F, typename G> bool function_equal(const F& f, const G& g);
J T
  • 4,946
  • 5
  • 28
  • 38
  • 3
    Wrong answer, `function_equal` is only useful to allow the comparison of function *wrappers* (`boost::function`) with function *objects* (functors or function pointers) (see [Comparing Boost.Function function objects](http://www.boost.org/doc/libs/1_47_0/doc/html/function/tutorial.html#id1362038)). Comparison of two function wrappers is not possible. (I admit that the documentation is not very clear about that.) – Luc Touraille Aug 30 '11 at 16:38
  • This is what I want. –  May 24 '16 at 12:19