[Preprocessor] Expand to nothin - BOOST_PP_SEQ_PUSH_BACK
Hi The BOOST_PP_SEQ_PUSH_BACK Macro expands to the seq with the extra element. But i don't want it to expand. I want to use the sequence later instead. How can i supress the expanding? I looked through the docs, but didn't find the right clue. I'm new too Preprocessorprogramming, so please excuse, if my question is stupid. Not the easiest thing, starting Preprocessor and Metaprogramming from nothing but the docs. Kind Regards Manuel Jung
Manuel Jung wrote:
Hi
The BOOST_PP_SEQ_PUSH_BACK Macro expands to the seq with the extra element. But i don't want it to expand.
So if the macro wouldn't expand it stays BOOST_PP_SEQ_PUSH_BACK(foo,bar) (literally), which obviously is not a sequence...
I want to use the sequence later instead.
Just do so (I'm not sure I understand what you're up to)! BOOST_PP_SEQ_PUSH_BACK is a trivial macro mostly for completeness: Instead of BOOST_PP_SEQ_PUSH_BACK(SEQ, c) you might as well say: SEQ (c) (subtle differences omitted, not to cause total confusion).
How can i supress the expanding?
As it's the very nature of the preprocessor to expand all macro invocations it sees, you can't in general. You can delay the expansion of function-like macros by supplying the argument list at a later point, #define MACRO(optional) foo optional() baz MACRO(BOOST_PP_EMPTY) // foo baz MACRO(BOOST_PP_IDENTITY(bar)) // foo bar baz // BTW: this techniques is used to avoid empty macro arguments // which provoke undefined behavior with C++98 or making sure it's connected at a later point: #define E() // Empty #define X(x) x // eXpand MACRO E () (BOOST_PP_EMPTY) // MACRO (BOOST_PP_EMPTY) X( MACRO E () (BOOST_PP_EMPTY) ) // foo baz X( MACRO E E () () (BOOST_PP_EMPTY) ) // MACRO (BOOST_PP_EMPTY) X(X( MACRO E E () () (BOOST_PP_EMPTY) )) // foo baz .
I'm new too Preprocessorprogramming, so please excuse, if my question is stupid. Not the easiest thing, starting Preprocessor and Metaprogramming from nothing but the docs.
Search the list archives, there should be lots of good material, around. http://news.gmane.org/gmane.comp.lib.boost.user http://news.gmane.org/gmane.comp.lib.boost.devel Regards, Tobias
Hi Thanks for your explanations. I'll need a moment to understand and read more. Maybe i'll be back here then. But thanks a lot for this! Greetings Manuel Jung
Manuel Jung wrote:
Hi
The BOOST_PP_SEQ_PUSH_BACK Macro expands to the seq with the extra element. But i don't want it to expand.
So if the macro wouldn't expand it stays BOOST_PP_SEQ_PUSH_BACK(foo,bar) (literally), which obviously is not a sequence...
I want to use the sequence later instead.
Just do so (I'm not sure I understand what you're up to)! BOOST_PP_SEQ_PUSH_BACK is a trivial macro mostly for completeness: Instead of
BOOST_PP_SEQ_PUSH_BACK(SEQ, c)
you might as well say:
SEQ (c)
(subtle differences omitted, not to cause total confusion).
How can i supress the expanding?
As it's the very nature of the preprocessor to expand all macro invocations it sees, you can't in general.
You can delay the expansion of function-like macros by supplying the argument list at a later point,
#define MACRO(optional) foo optional() baz
MACRO(BOOST_PP_EMPTY) // foo baz MACRO(BOOST_PP_IDENTITY(bar)) // foo bar baz
// BTW: this techniques is used to avoid empty macro arguments // which provoke undefined behavior with C++98
or making sure it's connected at a later point:
#define E() // Empty #define X(x) x // eXpand
MACRO E () (BOOST_PP_EMPTY) // MACRO (BOOST_PP_EMPTY)
X( MACRO E () (BOOST_PP_EMPTY) ) // foo baz X( MACRO E E () () (BOOST_PP_EMPTY) ) // MACRO (BOOST_PP_EMPTY) X(X( MACRO E E () () (BOOST_PP_EMPTY) )) // foo baz
.
I'm new too Preprocessorprogramming, so please excuse, if my question is stupid. Not the easiest thing, starting Preprocessor and Metaprogramming from nothing but the docs.
Search the list archives, there should be lots of good material, around.
http://news.gmane.org/gmane.comp.lib.boost.user http://news.gmane.org/gmane.comp.lib.boost.devel
Regards, Tobias
participants (2)
-
Manuel Jung
-
Tobias Schwinger