Justificación en Boost.Preprocessor ¡Usando macros en lugar de define simple?
-
14-11-2019 - |
Pregunta
Por ejemplo, BOOST_PP_ITERATE
y BOOST_PP_ITERATION
, como se ve en la respuesta de GMAN aquí , son macros de preprocesadores, sin parámetros.¿Hay alguna razón por la que no son simplemente simples define y se usan como tales sin ()
?
Solución
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.
Otros consejos
Presumably because they perform operations: consequently, their usage should make it clear that you are actually invoking something and not just using some constant.