Boost logo

Boost :

Subject: Re: [boost] Alternative implementation for BOOST_PP_VARIADIC_SIZE
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2011-11-14 15:16:00


On Mon, 14 Nov 2011 11:14:53 +0000, Gennadiy Rozental wrote:

> Yes. This all is "legal" and "valid", but does it have meaning? I doubt
> it.

Yes, it does. The preprocessor is a code generator. Arguments to macros
are sequences of preprocessing tokens and whitespace separations. Such a
sequence can be empty. The target languages of the code generator, C and C
++, have numerous syntactic constructs that have something (say "A") or
nothing as opposed to something or something else (say "A" or "B"). The
cv-qualifiers are only one of *many* such examples. It isn't const, const
volatile, volatile, or "nonconst". It's const, const volatile, volatile,
or nothing. (More accurately, it's (const | nothing) (volatile | nothing)
in either order.) However, this lack of syntactic symmetry is all over
the place. There is no "opposite-of-noexcept" keyword, there is no
"nonstatic" keyword, and the list goes on and on. The point being that
the manipulation and generation of nothing is perfectly valid.

> Show me sane example where one would develop macro FOO which takes two
> arguments and tell users to invoke it like this FOO(,) or FOO(a,) or
> FOO(a,b). Instead one can present a macro which takes variadic data and
> does different things depending on how many arguments passed (0, 1, or
> 2). So the invocations would look like FOO(), FOO(a), FOO(a,b) - much
> better IMO.

That's fine if the input to your FOO macro is constrained such that
emptiness is detectable in a way that is reasonable in the domain of
applicability. It isn't fine for the implementation of a general purpose--
domain agnostic--preprocessor metaprogramming library.

> FOO(,) is a stone in a road to awk-like hell and should be strictly
> forbidden from the end user code. It might only be used in some corner
> cases deep in library code and never exposed.
>
> So, all the theoretical corner cases aside FOO() should be invocation
> with zero arguments and FOO(a) with one.

Sorry, no. The language (preprocessor) forces the distinction between
nullary and unary at the point of definition of the macro. This is not
the underlying language and does not behave like the underlying language.
That is why similarities to Awk and other text-in/text-out languages
exist. This is also not a macro mechanism like those of Scheme and Lisp
(except for a loose correlation with read-macros).

Regards,
Paul Mensonides


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