Boost logo

Boost Users :

From: Rennie deGraaf (renniedegraaf_at_[hidden])
Date: 2007-05-07 14:16:03


Doug Gregor wrote:
> On May 4, 2007, at 7:51 PM, Rennie deGraaf wrote:
>> Could anyone please tell me why the following code fails to compile:
>>
>>> inline void rmfunc(std::list<boost::function<void()> >& funcs,
>>> boost::function<void()> f)
>>> {
>>> for (std::list<boost::function<void()> >::iterator
>>> i=funcs.begin(); i!=funcs.end(); ++i)
>>> {
>>> if (boost::function_equal(*i, *f))
>>> i = funcs.erase(i);
>>> }
>>> }
>> while the following does compile:
>>
>>> template <typename T>
>>> inline void rmfunc(std::list<boost::function<void()> >& funcs,
>>> const T& f)
>>> {
>>> for (std::list<boost::function<void()> >::iterator
>>> i=funcs.begin(); i!=funcs.end(); ++i)
>>> {
>>> if (boost::function_equal(*i, f))
>>> i = funcs.erase(i);
>>> }
>>> }
>> and seemingly equivalent code, placed in-line in the calling function,
>> also compiles?
>
> You cannot compare two boost::function objects directly, because it
> can't be implemented. See the first question on http://www.boost.org/
> doc/html/function/faq.html
>
> - Doug

I'm not trying to compare function object types or contents; I'm trying
to compare the objects themselves. In other words, I'm trying to check
if (&A == &B), not if (A == B). Is there a safe way to do this?

Rennie


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net