Boost logo

Boost :

Subject: Re: [boost] [preprocessor] missing IS_EMPTY documentation?
From: Wolf Lammen (ookami1_at_[hidden])
Date: 2010-09-03 12:59:18


-------- Original-Nachricht --------
> Datum: Fri, 3 Sep 2010 11:29:41 -0400
> Von: Lorenzo Caminiti <lorcaminiti_at_[hidden]>
> An: boost_at_[hidden]
> Betreff: [boost] [preprocessor] missing IS_EMPTY documentation?

> Hello all,
>
> Is there a reason why `BOOST_PP_IS_EMPTY()` is not part of
> Boost.Preprocessor reference documentation?
>
> 1) I think this macro is part of the library public API because it is
> in <boost/preprocessor/facilities/is_empty.hpp> (outside the "detail/"
> directory and same location as `BOOST_PP_EMPTY` which is documented).

I think it is not part of the API, because it does not conform to C90. You must not submit parameters to macros that expand to nothing, because C90 does not cover this situation

>
> 2) Is it OK to use `PP_IS_EMPTY()` to check if a macro expansion is
> actually empty or not? For example:
>
> #include <boost/preprocessor/facilities/empty.hpp>
> #include <boost/preprocessor/facilities/is_empty.hpp>
>
> #define X /* expand to nothing */
> #define Y BOOST_PP_EMPTY
> #define Z a b c BOOST_PP_EMPTY
>
> BOOST_PP_IS_EMPTY(X) // expand to 1
> BOOST_PP_IS_EMPTY(Y()) // expand to 1
> BOOST_PP_IS_EMPTY(Y) // expand to 0
> BOOST_PP_IS_EMPTY(Z()) // expand to 0
>
> Thank you for the clarification.

Even if you use a C99 compliant preprocessor, there are some pitfalls lurking around. It tests the emptyness of something that expands to an unsigned integer or an identifier only. Examples

#define A foo
#define B (foo)
#define C 1
#define D

BOOST_PP_IS_EMPTY(A) // ok
BOOST_PP_IS_EMPTY(B) // error
BOOST_PP_IS_EMPTY(C) // ok
BOOST_PP_IS_EMPTY(D) // ok

-- 
GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99 Euro/mtl.!*
http://portal.gmx.net/de/go/dsl

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