For example BOOST_PP_ITERATE
and BOOST_PP_ITERATION
, as seen on GMan's answere here, are preprocessor macros, without any parameters. Is there a reason they're not just simple defines and used as such without ()
?
Asked
Active
Viewed 290 times
2
2 Answers
4
Generally, function like macro can be used to prevent unintentional macro
expansion.
For example, assuming that we have the following macro call:
BOOST_PP_CAT( BOOST_PP_ITERATION, _DEPTH )
and we expect this will be expanded into BOOST_PP_ITERATION_DEPTH
.
However, if BOOST_PP_ITERATION
is an object like(non-functional) macro,
it will be expanded to its own definition before the token
BOOST_PP_ITERATION_DEPTH
is generated by concatenation.

Ise Wisteria
- 11,259
- 2
- 43
- 26
-
This seems to be it, bot not only for concatenation, but also to pass these macros around to other `BOOST_PP` macros, like `BOOST_PP_EMPTY` is often used for `BOOST_PP_ENUM(NUM,MYMACRO,BOOST_PP_EMPTY)`. – Xeo Apr 01 '11 at 14:59
1
Presumably because they perform operations: consequently, their usage should make it clear that you are actually invoking something and not just using some constant.

Luc Touraille
- 79,925
- 15
- 92
- 137
-
Okay, that may hold true for `BOOST_PP_ITERATE`, but what about `BOOST_PP_ITERATION`? That's only supposed to be used as your current iteration depth, afaik. – Xeo Mar 31 '11 at 12:04
-
Oh, I didn't notice you mentioned `BOOST_PP_ITERATION`. Well I guess the rationale is quite similar: since the result of `BOOST_PP_ITERATION` is variable, it makes sense to make it look like a function returning a value. Plus consistency, of course. – Luc Touraille Mar 31 '11 at 12:12
-
But now I see that `BOOST_PP_IS_ITERATING` does not use this convention... :-s ! – Luc Touraille Mar 31 '11 at 12:12