Compare two boost functions ::

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 :: functions with the same signature. What should I change to compile this code?

+7
source share
2 answers

You can not. Read the FAQ Frequency Up feature first entry:

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

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

+14
source

Do you want to compare signatures or equality of a functor (that two functors point to the same main memory address)? If its the last, you can use the interface provided by boost/function_equal.hpp :

Zoom function equals

 template<typename F, typename G> bool function_equal(const F& f, const G& g); 
-one
source

All Articles