Boost.Preprocessor: expansion stops, result is further expandable
Hello,
I'd like to thank everybody involved in creation of Boost.Preprocessor
for this cool piece of software, it does wonders.
I have a possibly naive question (I'm an autodidact) which involves
Boost.PP. I have stumbled upon strange behavior where the preprocessor
stops expanding but the output expands further if fed to the
preprocessor again.
Given these directives:
#include
On 19 June 2011 01:37, Roman Neuhauser
Why doesn't DAPHP_REGISTER_CLASSES expand all the way as DAPHP_REGISTER_CLASS does? Please enlighten me.
C macros can't be called recursively. Boost.Preprocessor uses a clever technique to get round that for some macros, but it doesn't seem to do it for BOOST_PP_SEQ_FOR_EACH, I'm not sure why, it might be too expensive to do for every macro. I think that one thing you can do (and this is pretty crummy) is to use BOOST_PP_SEQ_FOR_EACH_I for one of the calls and just ignore the index. Or alternatively you can use a macro that supports recursion, I think BOOST_PP_SEQ_FOLD_LEFT, BOOST_PP_SEQ_FOLD_RIGHT and BOOST_PP_FOR are possibilities.
# dnljms@gmail.com / 2011-06-19 17:45:00 +0100:
On 19 June 2011 01:37, Roman Neuhauser
wrote: Why doesn't DAPHP_REGISTER_CLASSES expand all the way as DAPHP_REGISTER_CLASS does? Please enlighten me.
C macros can't be called recursively. Boost.Preprocessor uses a clever technique to get round that for some macros, but it doesn't seem to do it for BOOST_PP_SEQ_FOR_EACH, I'm not sure why, it might be too expensive to do for every macro.
Ah, BOOST_PP_SEQ_FOR_EACH Remarks section doesn't include the "Previously, this macro could not be used inside ..." paragraph that's present elsewhere.
I think that one thing you can do (and this is pretty crummy) is to use BOOST_PP_SEQ_FOR_EACH_I for one of the calls and just ignore the index. Or alternatively you can use a macro that supports recursion, I think BOOST_PP_SEQ_FOLD_LEFT, BOOST_PP_SEQ_FOLD_RIGHT and BOOST_PP_FOR are possibilities.
I decided to abstain from using sequences inside the CXXEXT namespace. The inner BOOST_PP_SEQ_FOR_EACH is now BOOST_PP_LIST_FOR_EACH with input transformed by #define CXXEXT_SEQ_TO_LIST(seq) \ BOOST_PP_EXPAND(BOOST_PP_TUPLE_TO_LIST BOOST_PP_SEQ_TO_ARRAY(seq)) -- roman
participants (2)
-
Daniel James
-
Roman Neuhauser