Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2004-12-15 13:05:04


On Dec 15, 2004, at 12:47 PM, gast128 wrote:

> Ok thank you. We use boost function also as a client defined callback.
> Because
> there is no operator==, it is very hard to unregister. So we came up
> with a
> solution probably comparable to the signals unregister solution.

Are you sure that the provided operator== doesn't work? The motivation
for this formulation of operator== (other than the unimplementability
of the general case) was that it solved Herb Sutter's "delegate"
problem. For instance, you can write this:

template<typename Signature>
class delegate
{
   typedef boost::function<Signature> callback_type;
   std::list<callback_type> callbacks;

public:
   template<typename F> void register(const F& f) {
callbacks.push_back(f); }

   template<typename F> void unregister(const F& f)
   {
     typename std::list<callback_type>::iterator pos =
std::find(callbacks.begin(), callbacks.end(), f);
     if (pos != callbacks.end()) callbacks.erase(pos);
   }
};

        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