Boost logo

Boost :

From: William Kempf (sirwillard_at_[hidden])
Date: 2000-11-22 16:15:39


--- In boost_at_[hidden], Karl Nelson <kenelson_at_e...> wrote:
>
> [....]
> > > 2) Second it makes for really poor code clarity as the class
will
> > > have to implement all of the operator() even through it uses
> > > only one of them...
> > >
> > > class callback {
> > > ...
> > > return_type operator()() { ... }
> > > return_type operator()(P1 p1) { ... }
> > > return_type operator()(P1 p1,P2 p2) { ... }
> > > return_type operator()(P1 p1,P2 p2,P3 p3) { ... }
> > > return_type operator()(P1 p1,P2 p2,P3 p3,P3 p3) { ... }
> > > ...
> > > };
> >
> > The callback class doesn't have to implement all operator()
overloads, though the alternative requires deriving from a base class
which has the proper overload. The first option is slightly more
readable for the "callback" class itself, the second option gives the
best error messages (since only one operator() exists).
>
> I don't believe that deriving directly will work, or at least I
haven't
> seen one without the construction I showed above.

Look at Doug's implementation. All that would be required is to
derive from the "impl" class instead of containing it. He's done the
work or factoring out the unneeded overloads using a simple bit of
meta programming.

> > > 5) It caps the number of callback which limits the application
> > > somewaht. That is with the callback#, the user can always call
> > > the macro generator to produce another set of classes for a
> > > larger number of parameters.
> >
> > Not necessarily. In my original event library, I used this
technique and had scripts to generate the event classes. The only
reason this has yet to be done for any of the current callback
library candidates is that it is less manageable in the prototype
stage.
>
>
> However, this won't link unless all the code is compiled against
the
> same number.

In general, I don't think this is that big of an issue. If you
supply a reasonable number to begin with, it's very unlikely that
more will be needed. It's generally bad programming practice to
write functions that take large numbers of arguments to begin with.
Generate a callback that takes up to 10 arguments and I think there's
little danger of someone needing more.

Bill Kempf


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