Suggested extension to the preprocessor library

Hi, I've been using the preprocessor library quite extensively in my code, and have a suggested addition to it. I use the BOOST_PP_ENUM_XXX macros for rapidly creating lists of identical template parameters. For example, instead of template <typename T0, typename T1, typename T2, typename T3> I can just use template <ENUM_PARAMS(3, typename T)> I notice that there's also a "binary" version that takes two parts and suffixes the count onto each part. The problem I'm faced with is that I'm trying to construct parameter lists to other templates, but the actual parameters are embedded typedefs in the enumerated parameters. I know that was dense -- here's an example: typedef typename meta_func< typename T0::inner_type, typename T1::inner_type, typename T2::inner_type>::type; I don't see a way to do this with any of the ENUM_XXX macros. Maybe something like ENUM_SPLIT_PARAMS(COUNT, PREF, SUFF) that would generate PREF ## n ## SUFF? Thanks, Ryan

Ryan Saunders wrote:
here's an example:
typedef typename meta_func< typename T0::inner_type, typename T1::inner_type, typename T2::inner_type>::type;
I don't see a way to do this with any of the ENUM_XXX macros.
You can do this: #define INNER_TYPE(z, n, data) typename T##n::inner_type typedef typename meta_func< BOOST_PP_ENUM(3, INNER_TYPE, _) >::type; which is more general purpose than supplying a macro for every possibility.
Maybe something like ENUM_SPLIT_PARAMS(COUNT, PREF, SUFF) that would generate PREF ## n ## SUFF?
That wouldn't actually work in this case, since you can't concatenate a number onto a symbol - you probably mean PREF ## n SUFF. If you want this, you can do it yourself: #define ENUM_SPLIT_PARAMS(COUNT, PREF, SUFF) \ BOOST_PP_ENUM(COUNT, ENUM_SPLIT_PARAMS_OP, (PREF, SUFF)) #define ENUM_SPLIT_PARAMS_OP(z, n, data) \ BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n) \ BOOST_PP_TUPLE_ELEM(2, 1, data) Daniel

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Ryan Saunders
Hi Ryan.
typedef typename meta_func< typename T0::inner_type, typename T1::inner_type, typename T2::inner_type>::type;
I don't see a way to do this with any of the ENUM_XXX macros. Maybe something like ENUM_SPLIT_PARAMS(COUNT, PREF, SUFF) that would generate PREF ## n ## SUFF?
The ENUM_BINARY_PARAMS is the general form for this kind of stuff. You typically use it with INTERCEPT, such as: #include <boost/preprocessor/facilities/intercept.hpp> #include <boost/preprocessor/repetition/enum_binary_params.hpp> BOOST_PP_ENUM_BINARY_PARAMS( 3, typename T, ::inner_type BOOST_PP_INTERCEPT ) INTERCEPT (unsurpisingly) intercepts the numeric concatenation and expands to nothing. Normally the library avoids macros that have very specific uses. In fact, ENUM_PARAMS and ENUM_BINARY_PARAMS are probably the two most domain-specific macros in the library. If the usage scenario is too complex for ENUM_PARAMS or ENUM_BINARY_PARAMS (possibly with INTERCEPT), then you need to use the much more general form, ENUM. Regards, Paul Mensonides
participants (3)
-
Daniel James
-
Paul Mensonides
-
Ryan Saunders