
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