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