Boost logo

Boost :

From: Daniel James (daniel_at_[hidden])
Date: 2004-09-02 09:34:44


Toon Knapen wrote:
> Oops sorry. Here it is.
>
> Do you still want me to run following program ?

No, thanks for the preprocessor output. That's what's really needed.

> #line 14 "pp.cpp"
> 1 BOOST_PP_TUPLE_EAT_2 ( ~ , 0)
> 1 BOOST_PP_TUPLE_EAT_2 ( ~abc , 0)
> 0
> 0
> #line 22
> 1 BOOST_PP_TUPLE_EAT_2 ( ~ , 0)
> 1 BOOST_PP_TUPLE_EAT_2 ( ~abc , 0)
> 0
> 0

Well, it's almost worked, but those BOOST_PP_TUPLE_EAT_2's should expand
to nothing. I guess it needs another expansion. The following might
work. Please can you try it out?

In practice these macros will only get called from the other boost
macros which might cause these macros to expand fully? Paul will
understand this a lot better than me.

#include <boost/preprocessor/detail/split.hpp>
#include <boost/preprocessor/punctuation/comma.hpp>
#include <boost/preprocessor/punctuation/paren.hpp>
#include <boost/preprocessor/tuple/eat.hpp>

#define IS_NULLARY(x) \
     IS_NULLARY_2(BOOST_PP_SPLIT(1, IS_NULLARY_C x BOOST_PP_COMMA() 0)) \
     /**/
#define IS_NULLARY_2(x) x
#define IS_NULLARY_C() \
     ~, 1 BOOST_PP_RPAREN() \
     BOOST_PP_TUPLE_EAT(2) BOOST_PP_LPAREN() ~ \
     /**/

IS_NULLARY(()) // 1
IS_NULLARY(()abc) // 1
IS_NULLARY(+) // 0
IS_NULLARY(xyz) // 0

#define IS_UNARY(x) IS_NULLARY(IS_UNARY_C x)
#define IS_UNARY_C(a) ()

IS_UNARY((a)) // 1
IS_UNARY((a)abc) // 1
IS_UNARY(+) // 0
IS_UNARY(xyz) // 0


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