|
Boost : |
From: Ulrich Eckhardt (uli_at_[hidden])
Date: 2005-07-27 13:36:21
On Tuesday 26 July 2005 22:45, Rebooted wrote:
> In my program I need to store a map of signals, with an integer id
> corresponding to a signal in the map.
Some kind of map<id_type, signal_type>.
> Objects can request to be informed when another a specific message is
> emitted by connecting a member function to the signal in this map at
> the index corresponding to that message type.
IOW, objects can subscribe to events.
> However, since boost::signal inherits noncopyable, it cannot be stored
> in a map. What are the reasons for signal being noncopyable, and is
> there any chance this could be changed in the future?
(I'm walking on unknown grounds here, since I use libsigC++ instead, but last
time I looked, they were sufficiently similar - maybe some names are
different.)
The problem is that when you connect a slot to a signal, you get a reference
to that connection. Using that reference, you can also separate the
connection again. Now, what would happen when a signal was copyable? You
could end up with several connections, so which one would you disconnect?
Also, copying is not a trivial operation, so you'd rather avoid it.
Ideas:
Use Boost's function instead, which is copyable. Using bind, you can achieve
almost the same as with slots/signals. The exception is the automatic
disconnecting when the target object is destroyed, but that can also be
achieved by using weak_ptr and a wrapper function (maybe lambda would
eliminate even that).
Store a smart pointer instead of the signal itself. This would even speed up
operations on the map.
Uli
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk