Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-01-22 07:36:45

Hi Paul,

Here are two questions regarding the BOOST_PP_IS_*ARY macros:

My favourite use case is to allow macros to accept "user-friendly optional data
structures". E.g:

     #define DO_UNARY(macro,x) \

     #define DO_BINARY(macro,x) \

     DO_UNARY(A_MACRO,(elem)) // passes '(elem)' to A_MACRO
     DO_UNARY(A_MACRO,-) // expands to nothing

     DO_BINARY(ANOTHER_MACRO,(x,y)) // passes '(x,y)' to ANOTHER_MACRO
     DO_BINARY(ANOTHER_MACRO,-) // expands to nothing

or (the inverse logic for "non-generic scalar" arguments)

     #define OPTIONAL(x) \

     OPTIONAL(foo) // expands to 'foo'
     OPTIONAL( (none) ) // expands to nothing


Is it safe to use this technique with sequences, e.g.

     #define OPT_SEQ_CAT(seq) \

     OPT_SEQ_CAT(-) // expands to nothing
     OPT_SEQ_CAT((b)(o)(o)(s)(t)) // expands to 'boost'


And why do these components live in 'detail' (as opposed to 'tuple')? Because of



( Includes to preprocess the code in this post:

   #include <boost/preprocessor/seq/cat.hpp>
   #include <boost/preprocessor/tuple/eat.hpp>
   #include <boost/preprocessor/tuple/rem.hpp>
   #include <boost/preprocessor/control/iif.hpp>
   #include <boost/preprocessor/detail/is_unary.hpp>
   #include <boost/preprocessor/detail/is_binary.hpp>

Boost list run by bdawes at, gregod at, cpdaniel at, john at