1

After long time searching how to generate function with variadic argument i found some solution.



    #define item(z, n, _) \
    BOOST_PP_EXPR_IF(n, +) BOOST_PP_CAT(p, n) \
    #define add(z, n, _) \
    template inline T add( BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), T p) ) \
    { \
        return BOOST_PP_REPEAT(BOOST_PP_INC(n), item, ~); \
    } \
    BOOST_PP_REPEAT(ADD_MAX_ARITY, add, ~)
    #undef item
    #undef add

 

This is macros generate function, like T add(...){ return a+b....;}, and i founded how to do macro recursive expansion. Macro recursive expansion to a sequence. And my question may be possible to mix previous 2 solution to generate something like this?



    #define MPL(x) boost::mpl::vector{boost::mpl::char_{x}}
    #define MPL1(x,x1) boost::mpl::vector{boost::mpl::char_{x} ,boost::mpl::char_{x1} }
    ........
    #define MPLN(x,..xn) boost::mpl::vector{boost::mpl::char_{x}...,boost::mpl::char_{xn} }

 
Community
  • 1
  • 1
Topilski Alexandr
  • 669
  • 1
  • 12
  • 34
  • How interesting i solve this problem write: #define TUPLE_PRINT(n, i, data) data #define GEN_VECTOR_CHAR(n, i,unused)\ template< BOOST_PP_ENUM_PARAMS(i, char T) >\ struct initialize_vector_char<\ BOOST_PP_ENUM_PARAMS(i,T)\ BOOST_PP_COMMA_IF(i)\ BOOST_PP_ENUM(\ BOOST_PP_SUB(MAX_INITIALIZE_VECTOR_SIZE,i), TUPLE_PRINT, 0) >\ {\ \\body here}; BOOST_PP_REPEAT_FROM_TO(1, MAX_INITIALIZE_VECTOR_SIZE, GEN_VECTOR_CHAR, ~) We cannot write variadic #define(automaticaly) but we may write variadic templte or function. – Topilski Alexandr Jul 25 '12 at 07:20

0 Answers0