Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-04-11 15:56:44


Paul Mensonides wrote:
> > Not bad at all. Can we somehow get rid of the extra commas and
> > have the "canonical" placeholder names, e.g.
> >
> > CHAOS_PP_EXPR(CHAOS_PP_REPEAT(
> > 5
> > , ( CHAOS_PP_CAT_(_1, _0) = _0 )
> > , int x
> > ))
>
> Not without making it worse. Two fundamental problems exist here.
> First, the "canonical" placeholders. The only way that I could tell
> what they are is with concatenation. That would disallow direct
> input of operators, since token-pasting that produces multiple tokens
> is undefined behavior.

OK, understand.

> (I'm currently working on a paper for the committee to explicitly
> make this well-defined behavior, because it causes all sorts of
> problems. I can use the credentials of as many people as possible
> in this endeavour, because, after all, we're dealing with "extending"
> the preprocessor here.) I suppose I could define _1, _2, etc., but
> that is not a good idea for obvious reasons. The second problem with
> the above is that I can do absolutely nothing with the text between
> two operators (e.g. operators that are not commas or parentheses).
> Such as the following:
>
> + text +
>
> I cannot even get at "text" at all in order to deal with it.

That's too bad. But suppose I am willing to spell all non-alphabetic
tokens as macros, e.g.

    BOOST_PP_PLUS text BOOST_PP_PLUS

for your above example - would it change anything?

[snip]

> There are many things that are different. For instance, the entire
> library is implemented from the ground up to support variadics/
> placemarkers if using C99 (or C++ with those features). This alters
> the signatures a quite a few library primitives that use a data or
> state parameter. REPEAT is an example that doesn't have to change.
>
> REPEAT(count, macro, data)
> ^^^^
>
> In C99, this is:
>
> REPEAT(count, macro, ...)
>
> And the variadic parameters are passed straight through the mechanism
> and dealt with directly on the other end--which eliminates the need
> for excessive TUPLE_ELEM types of calls:
>
> #define DECL(s, n, id, init, ...) \
> __VA_ARGS__ id ## n = init; \
> /**/
>
> CHAOS_PP_EXPR(CHAOS_PP_REPEAT(
> 5, DECL, x, "Aleksey Gurtovoy", std::string<char,
> my_traits<char> >
> ))
>
> std::string<char, my_traits<char> > x0 = "Aleksey Gurtovoy";
> std::string<char, my_traits<char> > x1 = "Aleksey Gurtovoy";
> std::string<char, my_traits<char> > x2 = "Aleksey Gurtovoy";
> std::string<char, my_traits<char> > x3 = "Aleksey Gurtovoy";
> std::string<char, my_traits<char> > x4 = "Aleksey Gurtovoy";
>
> ...as an example.

Very interesting!

Thanks,
Aleksey


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