Subject: Re: [boost] [preprocessor] missing IS_EMPTY documentation?
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-09-08 12:06:17
On Mon, Sep 6, 2010 at 7:30 PM, Paul Mensonides <pmenso57_at_[hidden]> wrote:
> On 9/6/2010 3:17 PM, Wolf Lammen wrote:
>> I wrote wrt to BOOST_PP_IS_EMPTY:
>> "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"
>> The relevant portions of the standard makes it clear:
>> "If (before argument substitution) any argument consists of no
>> preprocessing tokens, the behavior is undefined." ... "After the arguments
>> for the invocation of a function-like macro have been identified, argument
>> substitution takes place" ... "Before being substituted, each argument's
>> preprocessing tokens are completely macro replaced as if they formed the
>> rest of the source file"
>> Paul Mensonides is right, an argument must not be empty, when it is
>> collected, but it may be at the moment when it is substituted for a
>> parameter. I was mislead by the double mention and meaning of
>> "substitute/substitution", but argument substitution (as opposed to
>> parameter substitution) is the combined process of expanding the argument
>> and substitution for a parameter, and checking
>> for emptyness takes place prior to "argument substitution".
>> I apologize for having given a wrong interpretation and hope this have not
>> lead to too much confusion.
> Luckily, it no longer matters in C and will no longer matter in C++ shortly.
Thanks a lot to all for the replies and clarifications. I think I
understand the situation.
I use IS_EMPTY more or less like this:
#define HAS_NO_OPTION(x) BOOST_PP_IS_EMPTY(x)
#define NO_OPTION BOOST_PP_EMPTY
#define XYZ_OPTION xyz BOOST_PP_EMPTY
HAS_NO_OPTION(NO_OPTION()) // expand to 1
HAS_NO_OPTION(XYZ_OPTION()) // expand to 0
This seems fine because I never pass an empty macro parameter (but
only parameters that eventually expand to empty, which is fine). Plus,
by construction, `x` only contains literals or numbers with no dot.
(MORE BACKGROUND: This is an implementation detail of my parenthesized
syntax pp-parsers. For example, a member function might or no be
`const`, so after parsing `const` is represented internally as either
`BOOST_PP_EMPTY` or `const BOOST_PP_EMPTY` within an array of parsed
function signature traits called `sign`. Then trait inspection macros
can be applied to check `IS_CONST(sign)`. These inspection macros
expand `BOOST_PP_EMPTY` and check for emptiness using
`BOOST_PP_IS_EMPTY()`. This implementation works on both GCC and
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk