Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2007-05-07 09:05:18


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


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