Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2005-02-17 18:23:17


"Paul Mensonides" <pmenso57_at_[hidden]> wrote

> How are you using SEQ_CAT? I ask because SEQ_CAT does an ordered
concatenation
> from left-to-right. A simple translation of the above:
>
> SEQ_CAT((STEP3)(STEP2)(STEP1 5))
>
> Will never result in a single STEP2STEP1 token (which is supposed to
expand to
> nothing). Instead, it will result, successively in STEP3 -> STEP3STEP2 ->
> STEP3STEP2STEP1 5.
>
> > (the above exersize may not make sence out of context. I
> > don't think the context is relevant, although I can provide
> > it if necessary)
>
> No, the context isn't necessary, though there may be a better way to do
whatever
> it is you're trying to do. The probable reason that SEQ_CAT is working is
that
> SEQ_CAT is doing more workarounds to force expansion on VC that should
have
> happened already (possibly, should have happened a long time ago).

I guess I need to provide the context :-)

I have a macro parameter that describes parameters of a template. This
macro parameter can come in one of two flavours, for example:

1) (class)(unsigned int)(bool)

2) a number. This means that the template has n type parameters.

I want to apply some "magic" to this macro parameter, that:

- in case 1 would not affect it;
- in case 2 convert it to something like (class)(class)(class)

My first attempt was to paste something on the left, like:

#define DO(x) BOOST_PP_CAT(STEP1, x)
#define STEP1(x) (x)
#define STEP11 (class)
#define STEP12 (class)(class)
...

To naive -- can't paste anything to '(' :-((

By the way, VC7 did allow me to do this -- this approach worked there. It
is GCC who complained (Not that this is good about VC71. If you disregard
PP, the VC71 is pretty good IMO, but far too tolerant).

So, I re-implemented it like this:

#define DO(x) BOOST_PP_SEQ_CAT(\
    (STEP3)\
    (BOOST_PP_CAT(STEP2, BOOST_PP_EXPAND(STEP1 x)))
)

#define STEP1(x) _(x)
#define STEP3STEP2_(x) (x)
#define STEP2STEP1

#define STEP31 (class)
#define STEP32 (class)(class)
...

Basically STEP1 is needed to add something to the sequence you can paste to,
STEP2 -- to remove the sideffect from the number, and STEP3 -- to do the
work as in the original implementation.
So:

(int)(class) --> STEP1 (int)(class) --> _(int)(class) -->
STEP2_(int)(class) --> STEP3STEP2_(int)(class) --> (int)(class)
2 --> STEP1 2 -->STEP2STEP1 2 --> [space]2 --> STEP32 -->(class)(class)

This also explains why I need EXPAND.

So do you think anything better can be done?

Regards,
Arkadiy


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