Boost logo

Boost :

From: Daniel James (daniel_at_[hidden])
Date: 2004-08-15 15:09:29


I've written an implementation of BOOST_PP_IS_UNARY which works for
Borland, and hopefully any other preprocessors which the current
implementation doesn't. It is:

     #define EAT2(x,y)

     #define IS_UNARY_CHECK(x) ~, 1 BOOST_PP_RPAREN() \
         EAT2 BOOST_PP_LPAREN() ~

     #define IS_UNARY(x) IS_UNARY_1(IS_UNARY_CHECK x, 0)
     #define IS_UNARY_1(x, y) IS_UNARY_2(x, y)
     #define IS_UNARY_2(x, y) y

For a non-unary argument, the expansion is simple:

     IS_UNARY(x)
=> IS_UNARY_1(IS_UNARY_CHECK x, 0)
=> IS_UNARY_2(IS_UNARY_CHECK x, 0)
=> 0

For a unary argument, it expands like this (I might have got the
expansion order slightly wrong but, hopefully, this illustrates how it
works):

     IS_UNARY((x)y)
=> IS_UNARY_1(IS_UNARY_CHECK(x)y), 0)
=> IS_UNARY_2(~, 1 BOOST_PP_RPAREN() EAT2 BOOST_PP_LPAREN() ~y, 0)
=> IS_UNARY_2(~, 1) EAT2(~y, 0)
=> 1

The same technique can be used for BOOST_PP_IS_NULLARY and
BOOST_PP_IS_BINARY.

So, if this is used as for borland, could these marcros be made
'public'? Also, with a full working BOOST_PP_IS_UNARY, I think it should
be possible to make BOOST_PP_SEQ_NIL act as an empty sequence, if I
write a patch to do that would it be accepted?

Daniel


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