|
Boost Users : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-03-28 15:43:48
On Friday 28 March 2003 02:41 pm, Alisdair Meredith wrote:
> I am trying to create a simple mechanism to register multiple callbacks
> with my class.
>
> My first simple-minded approach is to use
>
> std::list< boost::function2< [my params]> >
>
> Unfortunately, I cannot search this list to unregister callbacks, as any
> attempt to dereference a list::iterator tries to call the function,
> rather than return the function object. After spotting this problem in
> the standard algorithms I have been trying to hack around myself,
> explicitly calling operator* and even operator-> with no joy.
>
> Am I missing some easy way to get the function object out of the
> iterator as a value?
> And is this a bug in my compiler (BCB6) or a general issue for
> containers of function objects?
Dereferencing an iterator into that list should give you a reference to a
boost::function2 object. If BCB6 is calling that function object, it has a
Very Big Problem.
Granted, you wouldn't be able to search the list for a particular function
object anyway, because boost::function objects can't be compared. I suggest
either:
(1) associate some additional data with each callback that is unique to that
callback (e.g., an integer or string value) and use std::map<Key,
boost::function2<...> >, or
(2) return some kind of token (containing the iterator where the function
object was inserted), or
(3) use Signals to do #2 for you
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