Boost logo

Boost :

From: William Kempf (sirwillard_at_[hidden])
Date: 2000-11-22 13:17:01


--- In boost_at_[hidden], Douglas Gregor <gregod_at_r...> wrote:
> On Tue, 21 Nov 2000 21:19:25 -0800
> Jesse Jones <jejones_at_a...> wrote:
>
> > I've uploaded a new version of my callback classes (see the
Callbacks2
> > directory in the vault). Like Doug Gregor's this version has the
nice
> > property of not requiring clients to encode the number of
arguments in the
> > callback class name.
>
> Here are a few questions/comments (beyond what has already been
discussed):
>
> 1) Why are all of the callback operator() overloads const? I can
see reason in offering both a const_callback and a callback class,
but I don't see how these operators are always const.

I'm not sure how to address this one yet. Any language lawyers that
have an opinion?

> 2) The usage of template metaprogramming (mostly SWITCH/CASE) makes
me wonder about portability... Has anyone tried to compile this on
MSVC++?

I've not compiled Jesse's version yet, but in general template
metaprogramming *can* work with VC++ so long as you avoid partial
specialization.
 
> 3) We have three different sets of semantics for callback copying -
explicit reference counting (which your implementation uses),
shared_ptr reference counting (which I use), and cloning (Peter
Dimov's function_ptr). Cloning is safest (but inefficient), whereas
shared_ptr is currently not thread-safe and explicit reference
counting could easily be made safe. What is the goal of the Boost
callback library regarding thread safety vs. efficiency?

I'm not sure how "easy" it is to make explicit ref-counting thread
safe. If there's any experts on this specific threading issue I'd
love to hear about issues involved and possible examples of thread
safe code (even if non-portable). That said, if explicit ref-
counting can be made thread safe so can boost::shared_ptr. Making
shared_ptr thread safe may take some thought because you don't want
to add overhead for single threaded programs (or even just single
threaded usages within a multi-threaded program). So explicit coding
may be helpful in early stages, but it should be replaced with
boost::shared_ptr at some point.

As for ref-counting vs. cloning... that's a trickier question. I'm
leaning in favor of ref-counting since a callback is likely to be
passed around frequently. However, I'd love to hear a list of pros
and cons from people for both strategies just to make sure I've not
missed any that could change my opinion (and to help others formulate
their own opinions as well).

> 4) Making callback an AdaptableBinaryFunction is a good idea,
though it is incorrect because not all callback's will be adaptable
binary functions, and the typedefs will be incorrect in those cases
(e.g., callback<int, int> will be missing the "argument_type"
typedef).

I don't know if it's even a good idea. Lambda and other such
libraries should allow you to do binding with out the restrictions
required by AdaptableBinaryFunction.

Bill Kempf


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk