containers of boost::function objects
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? -- AlisdairM
Vaclav Vesely wrote:
Have you tried to use the Boost Signals library?
Tried it a while back, but either did not understand correctly or hit compiler (or IIRC, linker) issues. It looks too similar to what I am attempting now though, so I will look again a.s.a.p. Thanks for the reminder. -- AlisdairM
FYI, I've used boost::signals from 1.29.0 and 1.30.0 under BCB6 with no problems. The only (slight) issue for us is that they aren't thread safe, so have had to create our own wrapper around them to make them so. Apart from that, they work well. Cheers Russell Alisdair Meredith wrote:
Vaclav Vesely wrote:
Have you tried to use the Boost Signals library?
Tried it a while back, but either did not understand correctly or hit compiler (or IIRC, linker) issues.
It looks too similar to what I am attempting now though, so I will look again a.s.a.p. Thanks for the reminder.
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
Douglas Gregor wrote:
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.
I'll look into this further next week, and see if I can produce an interesting test case. As you point out, what I am trying to do here is not valid anyway!
Granted, you wouldn't be able to search the list for a particular function object anyway, because boost::function objects can't be compared.
Yup, I spotted I had mis-read the docs right after posting. My bad.
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
>, or
Yes, this is what I have done <g>
(3) use Signals to do #2 for you
I tried looking at signals a while back, but hit problems with either my understanding or the compiler. However, solving this sure makes me feel like I'm re-inventing the wheel! It's high on my list of things to look into after the ACCU. -- AlisdairM
participants (4)
-
Alisdair Meredith
-
Douglas Gregor
-
Russell Hind
-
Vaclav Vesely