On 6/18/07, Tobias Schwinger
Server Levent Yilmaz wrote:
On 6/18/07, *Roman Perepelitsa*
mailto:roman.perepelitsa@db.com> wrote: Tobias Schwinger
http://isonews2.com> writes: > Yep, here's another dirty trick : > > #include
> > #define SPECIAL (whatever) > #define IS_SPECIAL BOOST_PP_IS_UNARY > > IS_SPECIAL(a) // 0 > IS_SPECIAL(b) // 0 > IS_SPECIAL(SPECIAL) // 1 > > It isn't entirely portable to older preprocessors (that's why this code > lives in preprocessor/detail) but should work with latest versions of
> the widely-used compilers.
This also works:
#include
#include #define SPECIAL #define IS_SPECIAL(x) BOOST_PP_IS_EMPTY(BOOST_PP_EMPTY() x)
This is great. I am really surprised that it works in a comma separated argument list, and that you can pass around a funny array (4, (a1, a2, , a3) ), and work on it as expected.
This behavior, however, is not backed by the current standard!
That's why Roman added BOOST_PP_EMPTY(), I guess, so the argument itself isn't empty and expands to emptiness during expansion of the invoked macro.
Take a look at this: #define SPECIAL #define IS_SPECIAL(x) BOOST_PP_IS_EMPTY(BOOST_PP_EMPTY() x) #define MACRO(i,z,array) IS_SPECIAL( BOOST_PP_ARRAY_ELEM(i, array) ) #define ENUM( n, tuple ) BOOST_PP_ENUM( n, MACRO, (n, tuple) ) ENUM( 3, ( arg1, , arg3) ) //1 ENUM( 3, ( arg1, SPECIAL, arg3) ) //2 In this context, can we safely say that 2 complies with standards more than 1? cheers, L. -- Server Levent Yilmaz Mechanical Engineering University of Pittsburgh