Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-04-10 09:58:56


I've started using the technique recommended by Aleksey below.

unfortunately in practice it isn't quite what I'm after:

1. I need to pre-generate a large number of repetitions for most EDG
compilers, which it seems basically can't handle any PP lib constructs,
making me wonder how much the PP lib is really buying me.

2. It moves the generated examples far from the PP code which they help
to document.

3. I still don't have a good way to quickly clean up the output. I think
it would be fairly trivial to implement something, but that's an extra
step I haven't taken yet.

4. Things aren't so simple when there conditional compilation to work
around compiler bugs is involved.

3 and 4 are not too serious. 2 could be fixed by putting the generated
code in the same file. 1 is unfortunately a limitation of many real
compilers for which there is no known workaround :(

Anyway, I think I'm going to stick with it. Once you get a feeling for
how to use the lib, its input is not significantly less-readable than my
Python-based hack, and it does offer the user the advantage of dynamic
library extensibility. I'd still /really/ like a way to compare two C++
token streams. When converting handwritten C++ to PP stuff having a way
to verify your work is indispensable. This point and #3 I could probably
handle with a simple Python script.

-Dave

----- Original Message -----
From: "Aleksey Gurtovoy" <agurtovoy_at_[hidden]>

> David Abrahams wrote:
> > It's not what I'm after. I want the standard release to contain
> > debuggable, expanded code for the commonly-used low-repetition cases
> > (without the need for special user configuration), and for higher
> > repetition counts I would like to use the PP lib.
>
> I guess I failed to explain my suggestion properly :). Here is another
try:
>
> [my_header.hpp]
> #include "my_library/preprocessor.hpp"
>
> #if !defined(BOOST_MY_LIBRARY_GENERATOR_MODE)
> # include "my_library/preprocessed/my_header.hpp"
> # define BOOST_MY_LIBRARY_REPETITION_START 5
> # define BOOST_MY_LIBRARY_REPETITION_END 15
> #else
> # define BOOST_MY_LIBRARY_REPETITION_START 0
> # define BOOST_MY_LIBRARY_REPETITION_END 5
> #endif
>
> #define AUX_MY_CONSTRUCT_GEN(i) \
> template< BOOST_MY_LIBRARY_PP_PARAMS(i, typename T) > \
> struct my_construct { /* more stuff */ }; \
> /**/
>
> BOOST_MY_LIBRARY_PP_REPEAT_FROM_TO(
> BOOST_MY_LIBRARY_REPETITION_START
> , BOOST_MY_LIBRARY_REPETITION_END
> , AUX_MY_CONSTRUCT_GEN
> )
>
> #undef AUX_MY_CONSTRUCT_GEN
> #undef BOOST_MY_LIBRARY_REPETITION_END
> #undef BOOST_MY_LIBRARY_REPETITION_START
>
> Now, if you just simply include "my_library/preprocessor.hpp", you
will get
> exactly that - a debuggable, expanded code for the commonly-used
> low-repetition cases (5, in above example), and the raw
> preprocessor-generated code for the rest of the cases (5-15). You
generate
> the expanded code by invoking the compiler in preprocessing-only mode
with
> 'BOOST_MY_LIBRARY_GENERATOR_MODE' macro defined, and save the result
as
> "my_library/preprocessed/my_header.hpp". The whole thing should be
pretty
> easy to automate.


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