Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 用于生成boost::mpl::vector序列的宏_C++_Boost Mpl - Fatal编程技术网

C++ 用于生成boost::mpl::vector序列的宏

C++ 用于生成boost::mpl::vector序列的宏,c++,boost-mpl,C++,Boost Mpl,在花了很长时间研究如何用可变参数生成函数后,我找到了一些解决方案 #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_REPEA

在花了很长时间研究如何用可变参数生成函数后,我找到了一些解决方案



    #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

这是宏生成函数,如T add(…){returna+b…;}, 我发现了如何进行宏递归扩展。 我的问题是,是否可以将前两种解决方案混合在一起生成类似的结果



    #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} }


我解决这个问题的有趣之处在于:定义元组打印(n,i,data)数据定义生成向量字符(n,i,unused)\template\struct initialize\u VECTOR\u CHAR\{\\ body here};我们不能写变量定义(自动),但我们可以写变量模板或函数。