Topic: Standard Library TR: something missing


Author: quintus_x@hotmail.com (P G)
Date: Sat, 7 Aug 2004 04:55:16 GMT
Raw View
I have been looking through the potential additions to the c++ library
(tuples, function, bind, smart pointers, reference wrappers) and I'm
very pleased. Each library is not only brilliant in its own right but
interact with the others to produce elegant solutions. (For example,
bind and smart_ptr can be combined to create a convenient scopeguard,
though it might be less efficient than Alexandrescu's dedicated
implementation due to virtual function dispatch and memory
allocation).

However, I think one boost library is sorely missing from the list of
proposals. I consider boost::Signals to be the perfect complement to
boost::Function. The signals sister library adds (among other things)
the important ability to attach mutiple functions to a single
'pointer' and invoke them all with a single command. Since I foresee
boost::function being used to implement the observer pattern I also
expect repeated reinvention of the signals library . However, it may
not even be trivial to implement properly. From my limited
observations, this is exactly the kind of facility that has typically
been standardized.

The signals library uses a connection object to represent a
subject-observer connection. The connection object can then be used to
query or discontinue the relationship. Some would prefer that
disconnection involve reuse of the function/functor (like .NET
delegates) thus:

sig.connect(f);
sig.disconnect(f);

I prefer the connection object approach. Where f is a simple function
the above might seem superior (no need to keep a separate object) but
we could easily have

sig.connect(bind(f, a, b, bind(g, x, y)));
sig.disconnect(bind(f, a, b, bind(g, x, y)));

where we have to repeat a complex function composition expression

or

f = bind(f, a, b, bind(g, x, y));
sig.connect(f);
sig.disconnect(f);

in which case we are storing a copy of something we may not otherwise
need.

On the other hand, I don't know if I like the name signals for the
standard library (C already has signals); std::multi_function (for
example) might be more appropriate to emphasize the link with
function.

In conclusion, I'll just add that I have nothing to do with the design
or maintenance of the boost signals library. I'm just a c++ enthusiast
interested in whether there may be any plans at all to incorporate
some form of multicast delegate into the standard library. If there
isn't, I hope I've aroused some interest.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]