Razionale su boost.preprocessore con macro invece di semplici definisce?
-
14-11-2019 - |
Domanda
Ad esempio BOOST_PP_ITERATE
e BOOST_PP_ITERATION
, come visto su AnswerSers Qui , sono macro preprocessore, senza parametri.C'è una ragione per cui non sono solo semplici definimenti e usati come tali senza ()
?
Soluzione
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.
Altri suggerimenti
Presumably because they perform operations: consequently, their usage should make it clear that you are actually invoking something and not just using some constant.