Boost logo

Boost Users :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-11-14 07:45:08


On Wednesday 13 November 2002 06:10 pm, electricsnark wrote:
> I need to make a registry of callback functions, which are in
> the form of member functions of objects of various types.
[snip code snippet]
> However, before adding the boost::function to the vector, I want
> to make sure that the callback function isn't already in there.
> Unfortunately, I can't just look at value of the pointer fp - I
> need to get to the address of the actual callback function that
> is to be executed. But I can't figure out how to get there.

Unfortunately, you can't get the address or type of the underlying function
object from a boost::function object. But even if you could, it wouldn't help
much, because you can't compare the function objects returned by Boost.Bind.

One common workaround is to explicitly keep "tokens" around that represent a
callback function that is in the list. The token could be, for instance, an
iterator into the callback list (not for a vector!). The Signals library does
this with the "signals::connection" class, which can be used to query the
status of the connection and/or disconnect the connection (e.g., remove the
callback function from the vector).

You might also want to take a look at the Signals library. It may do what you
need.

        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