Subject: Re: [boost] [preprocessor] Warning: Incoming
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-06-27 17:25:15
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:
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.
(__VA_ARGS__, 2, 1)
(__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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk