|
Boost : |
Subject: Re: [boost] [Boost.Preprocessor] FOREACH( MACRO, ... )
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2010-02-16 21:51:49
I now understand why Boost.Preprocessor doesn't support variable argument macros. Visual Studio has completely broken support and fails to expand __VA_ARGS__ into multiple tokens. Thus what works beautifully on G++ fails completely on VC++.
Are there any known workarounds or will I need to ask the user of my macros to specify the number of arguments and then be limited to supporting the number of arguments I happen to enumerate?
Dan
On Feb 16, 2010, at 10:03 AM, Daniel Larimer wrote:
>
> On Feb 16, 2010, at 1:53 AM, joel falcou wrote:
>
>> Daniel Larimer wrote:
>>> Is there a reason why Boost.Preprocessor does not have many (any?) utilities for variadic macros?
>>> <snip>
>>> FOREACH( CASE, a, b, c, d, e)
>>> case a: case b: case c: case d: case e:
>>>
>> Isn't it what BOOST_PP_REPEAT and BOOST_PP_TUPLE is for ?
>>
>
> Clearly BOOST_PP_REPEAT is useful, but you need to know the number of arguments to successfully use it. Thus there need for PP_NARG(...), which for some reasons boost PP does not provide. So, I suppose that anyone with some experience with the pre-processor could come up with a FOREACH macro, it still seems much easer to write FOREACH(M,p1,p2,...) than
> what I have below (which is an improvement over what I sent before)
>
> #define PP_FOREACH_ARRAY( ... ) (PP_NARG(__VA_ARGS__) , ( __VA_ARGS__ ) )
> #define PP_FOREACH_ELEM(z,n,data) BOOST_PP_ARRAY_ELEM( BOOST_PP_ADD(n,1), data )
> #define PP_FOREACH( A, ... ) BOOST_PP_REPEAT( PP_NARG(__VA_ARGS__), PP_FOREACH_ELEM, PP_FOREACH_ARRAY(A,__VA_ARGS__) )
>
> You will notice that even BOOST_PP_TOUBLE_TO_LIST( ) requires that you know the size first.
>
> Most developers do not know the preprocessor in and out and so a simple FOR_EACH() macro could help them.
>
>> --
>> ___________________________________________
>> Joel Falcou - Assistant Professor
>> PARALL Team - LRI - Universite Paris Sud XI
>> Tel : (+33)1 69 15 66 35
>>
>>
>> _______________________________________________
>> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk