Boost logo

Boost :

From: Doug Gregor (gregod_at_[hidden])
Date: 2001-04-09 22:38:44

On Monday 09 April 2001 11:02, you wrote:
> From: Doug Gregor [mailto:gregod_at_[hidden]]
> > This has been discussed, and any_function (or "function" as it
> > will likely be renamed) is at the very least a starting point
> > for a full signals/slots library.
> Sorry if this is too big a question, but could you elaborate a bit on
> possible uses for a signals/slots library and why you'd use signals/slots
> over other methods?

Signals/slots are great when you need multicasting callbacks/events where the
source(s) and/or target(s) may be connected or destroyed at any time -
signals/slots manage all of this internally. For instance, if I have:

// at global scope
any_function<int, float, float> foo;

// later on, in a member function
foo = bind(this, &Bar::my_foo);

If the object represented by "this" is destroyed, the line:

foo(5.5, 33.3);.

will cause a segmentation fault because any_function does not know that the
function object it is pointing to has disappeared. With a signal/slot system,
the slot will notify any signals it is attached to when it disappears. So the
code would be rewritten as:

// global scope
signal<int, float, float> foo;

// later
class Bar {
  slot<int, float, float> foo_slot;

  // in a member function
  foo_slot = bind(this, &Bar::my_foo);
  foo = foo_slot;

When the slot object foo_slot is destroyed on Bar's destruction, it will
unregister itself from the signal "foo" automagically. Likewise, if the
signal is destroyed it notifies all of the slots it points to.

Additionally, signals will have the ability to decide how to combine results
from any number of different slot targets. For instance, the "foo" signal
might have 100 slots connected to it, so it must decide how to take the 100
integer results and return a single result.

The most often cited use of signals/slots (in my experience) is for GUI
systems, which require many events and in which many widgets are created or
destroyed. Tracing and updating lists of any_function objects would be a


Boost list run by bdawes at, gregod at, cpdaniel at, john at