
On 6/27/2011 5:25 PM, Mathias Gaunard wrote:
On 06/27/2011 10:37 PM, Edward Diener wrote:
May I suggest the addition of a macro that strips parentheses but only if they are present?
I do not think this is possible. But I am out of the loop regarding pp-lib additions and Paul would really know if this could be done.
Code to do this was already given on the Boost ML by Steven Watanabe: <http://article.gmane.org/gmane.comp.lib.boost.user/61011>
You are right and Steve came up with his technique in answering my own question.
I've already been using this for a year in my code, and it works fine.
There is one little caveat with the above code, it's not strictly conforming to C99/C++0x so it doesn't work with Wave. Replacing (__VA_ARGS__, 2, 1) by (__VA_ARGS__, 2, 1, 0)
fixes the problem.
I have found this to be very useful for passing arguments that contain commas easily.
Can you give an example of what you are trying to do ?
Consider something like
BOOST_FOREACH(std::pair<A, B> a, mymap)
this fails because the preprocessor sees it as three arguments.
Assuming BOOST_FOREACH was using STRIP_PARENS on its arguments, you could do
BOOST_FOREACH((std::pair<A, B> a), mymap)
in the cases where it is necessary.
This is actually pretty much a requirement when you want to write macros that take template with multiple parameters as arguments.
Tt is a good example. This has led me to work on some macros for pp-lib, which uses variadics, which can tell whether a macro parameter is a tuple, array, seq, or list. Then in your case you can go: #define STRIP_PARENS(x)\ BOOST_PP_IIF(BOOSTPP_IS_TUPLE(x),BOOST_PP_TUPLE_ENUM(x),x)