Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2005-02-18 09:56:25


"Paul Mensonides" <pmenso57_at_[hidden]> wrote

> This will work on most compilers (including VC)...
>
> #include <boost/preprocessor/control/iif.hpp>
> #include <boost/preprocessor/detail/is_unary.hpp>
> #include <boost/preprocessor/repetition/repeat.hpp>
> #include <boost/preprocessor/tuple/eat.hpp>
>
> #define TRANSLATE(x) \
> BOOST_PP_IIF( \
> BOOST_PP_IS_UNARY(x), \
> x BOOST_PP_TUPLE_EAT(3), BOOST_PP_REPEAT \
> )(x, TRANSLATE_2, ~) \
> /**/
> #define TRANSLATE_2(z, n, _) (class)
>
> TRANSLATE( (class)(unsigned)(bool) )
> // --> (class)(unsigned)(bool)
>
> TRANSLATE( 3 )
> // --> (class)(class)(class)
>
> This will work on most preprocessors, but not on those that use the
Borland
> configuration. Thanks to Daniel James, I do have a workaround for that
bug for
> Borland in particular, but I don't have verification that it works on
other
> preprocessors that use that configuration (so it has to wait until I can
> separate the implementations).

This definitely has a benefit of not having to provide multiple defines (but
rather rely on ones in the Boost.Preprocessor). However, it uses some
internal feature, IS_UNARY, which I guess is not a huge drawback since the
suggestion comes from the author :-) The portability issue is somewhat of
concern -- I would not like to compromise it because of this nicety
feature...

Do you think my other suggestion might be more portable?

#define TRANSLATE(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)
...

Regards,
Arkadiy


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