Boost logo

Boost :

Subject: Re: [boost] [preprocessor] Warning: Incoming
From: Edward Diener (eldiener_at_[hidden])
Date: 2011-06-29 10:54:35


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>
>
> 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.

As a side note, since STRIP_PARENS needs variadic macros anyway,
BOOST_FOREACH could take its arguments as variadic data without needing
the end-user to put parens around its first argument when an embedded
comma is present. Of course this would need for Eric Niebler to change
BOOST_FOREACH to support variadics when present.

Nonetheless macros using variadics to identify pp-lib data types on the
fly might still be useful and I have already come up with a pretty good
IS_TUPLE. Whether an IS_ARRAY, IS_LIST, or IS_SEQ is posible I shall see.

I will probably end up putting any additions in my VMD library for the
time being and if Paul decides that he wants them for pp-lib sometime in
the future they will eventually go there.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk