compare two boost::function
vo开发者_Go百科id 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 ?
You can't. Read the boost function FAQ's first entry:
- 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. ...
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);
精彩评论