Boost logo

Boost :

Subject: Re: [boost] Alternative implementation for BOOST_PP_VARIADIC_SIZE
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2011-11-12 20:20:01

On Sat, 12 Nov 2011 11:52:33 +0000, Gennadiy Rozental wrote:

> Lorenzo Caminiti <lorcaminiti <at>> writes:

> Frankly, I do not have time to read through the whole discussion. I am
> not a language lawyer, but for what it worth my version works on all
> compilers I have tried and looks to be perfectly legal (to me). I do
> know about one limitation. It's where __VA_ARGS__ ends with macro
> function which produces comma when evaluated. It's very rare case though
> and even if it's possible to implement solution that deals with it (look
> here:
> ), I find the complication does not worth the trouble.
> If Edward or Paul care to comment it might be easier for them to point
> to any shortcomings in my solution (if any).

You cannot detect emptiness in the general case (even excluding
pathological input such as unbalanced parentheses). This is simply a
fact. You can attack the problem in a variety of different ways, but all
of them have limitations that restrict the domain on input.

Regardless, the scenario here is fundamentally wrong-headed. A macro
argument may be empty, but that does not change the number of arguments.

#define A(...)

A() // one argument (*not* zero arguments)
B(,) // two arguments
C(,,) // three arguments


A( ) // one argument containing a space

The only to have a function-like macro that takes zero arguments is to
define the macro as nullary.

The bottom line here is that arguments to macros are sequences of
preprocessing tokens and whitespace separations which, according to > C99
and > C++11, may be an empty sequence.

Paul Mensonides

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