Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2006-08-30 17:27:50


> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Paul Mensonides

> The "ctor_template.hpp" header (as it currently exists) is
> such a function, but
> its initial call (the one that starts the iteration) is done
> by the client, not
> the file-iteration mechanism. You have to write that file as
> if it is a
> function--not a header. But you should also provide a normal
> header that
> defines the interface to the function (i.e.
> BOOST_FORWARDER_CTOR_TEMPLATE()) and
> includes the files needed by the function.

I see that you updated your library! A couple of quick notes...

1) Because the macro names are uppercased (annoying, but necessary), the
comments at the top of the "detail/ctor_template.hpp" file need to be updated.

2) The #error directive on line 18 has an unmatched double-quote. Any
standard-compliant preprocessor will yield a tokenization error, as the contents
of #error directives are still tokenized (just like everything else except
comments). Simple fix: add a closing double-quote.

Regarding what the generated code is doing (as opposed to what the generator
code is doing), the major problem with forwarding without language support is
that it is a combinatorial problem--rather than linear. I.e. you really need
various combinations of const and-or volatile and non-cv-qualified references in
generic libraries. E.g. to support exactly two parameters, you need 16
functions.

If you ignore volatile (which you could get away with in 99% of situations), you
can reduce the above to just 4 functions.

Increasing the number of parameters exponentially increases the number of
functions needed. E.g. with three parameters, you need 8 functions.

IOW, you need Q^N functions to support N parameters with Q possible qualifiers.
This, in turn is additive when you support 0 to N parameters: 1 + Q + Q^2 +
Q^(N-2) + Q^(N-1) + Q^N. In other words a summation of Q^N with N ranging from
0 to your maximum arity. So you need, for example, 31 functions total to handle
up to 4 parameters where each parameter can be const or non-const qualified.
With volatile, you need 341 functions total to handle up to *just* 4 parameters.
At up to 5 parameters, the number of functions is well over a thousand. At 6,
over 5000. It breaks the million function mark at 10 parameters. At up to 10
parameters, but ignoring volatile, it is only a "measily" 2047 functions.

In any case, it is still reasonable up to 5 parameters if you're ignoring
volatile. I know that Dave implemented this kind of forwarding for an operator
new workalike that returned a smart pointer. (With perfect forwarding, you can
design a reference-counted smart pointer so that it doesn't require a double
allocation.)

Regards,
Paul Mensonides


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