Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-04-03 20:53:39


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.

Aleksey

P.S. Just in case if you want to try the above, here is
BOOST_MY_LIBRARY_PP_REPEAT_FROM_TO macro definition:

#define BOOST_MY_LIBRARY_PP_REPEAT_FROM_TO_FUNC(i, of) \
    BOOST_PP_TUPLE_ELEM(2, 1, of)( \
        BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(2, 0, of), i) \
        ) \
/**/

#define BOOST_MY_LIBRARY_PP_REPEAT_FROM_TO(i, j, f) \
    BOOST_PP_REPEAT_2ND( \
          BOOST_PP_SUB(j, i) \
        , BOOST_MY_LIBRARY_PP_REPEAT_FROM_TO_FUNC \
        , (i, f) \
        ) \
/**/


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