From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-10-16 09:55:51
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Darren Cook
> Hi Paul,
> I'm trying to use your example code now, and also to
> understand it, so I've
> got a few questions.
> 1. For "#define params(z, n, _)" is "_" a convention
> meaning a parameter
> that is not used? Is 'z' being used behind the scenese
> somewhere, or could I
> also write:
> #define params(_, n, _)
> #define params(_1, n, _2)
The _ is just a parameter that I didn't use, so I gave it a
non-meaningful name. The parameter itself is for auxiliary data that
you pass through the repetition primitive to your macro (e.g. "params"
here). For example,
#define target(z, n, user) < n : user >
BOOST_PP_ENUM(3, target, Darren)
target(2, 0, Darren) target(2, 1, Darren) target(2, 2, Darren)
which, in turn, expands to:
< 0 : Darren > < 1 : Darren > < 2 : Darren >
In other words, it's for whatever auxiliary data that you might need
when you're macro gets invoked, which lets you use macros for more than
one specific purpose.
The 'z' parameter is the next available repetition dimension. It can be
used for multidimensional repetition. Here, you're generating a
multidimensional result, but the #include mechanism is handling the
outer dimension. You can effectively ignore the 'z' parameter here.
(Actually, you can always ignore it if you want, see the "reentrancy"
topic in the documentation.)
> 2. What is the meaning of "~" here:
> void func(BOOST_PP_ENUM(arity, params, ~))
> I couldn't see this used in any of the examples, nor mentioned in
> BOOST_PP_ENUM reference page.
C++ requires that you pass something as a parameter to a macro--even if
you ignore it, which is what happens here. (C99 allows you to pass an
empty argument.) So, you could use anything:
void func(BOOST_PP_ENUM(arity, params, !))
void func(BOOST_PP_ENUM(arity, params, "ignored"))
It doesn't matter, so long as it isn't empty.