How to “concatenate” boost::mpl::vectors

左心房为你撑大大i 提交于 2019-12-19 16:35:47

问题


I have to different vectors

mpl::vector<Type1, Type2...>
mpl::vector<Type3, Type4...>

I'd like to "concatenate" them to form:

mpl::vector<Type1, Type2, Type3, Type4...>

This would allow me to prepare vector templates and reuse them afterwards. There are different solutions to my problem, but this approach seems most appropriate to me.

Thanks...


回答1:


The libaray native supported function boost::mpl::joint_view is probably a better choice. It is optimized and lazy-evaluated.

http://www.boost.org/doc/libs/1_55_0/libs/mpl/doc/refmanual/joint-view.html




回答2:


Like this:

// include the appropriate headers
typedef mpl::vector<Type1, Type2> first_type;
typedef mpl::vector<Type3, Type4> second_type;
typedef mpl::copy<first_type::type, mpl::back_inserter<second_type> >::type concat_type;



回答3:


You can use mpl::copy, which uses mpl::fold internally.

typedef mpl::vector<T0, T1> s0;
typedef mpl::vector<T2, T3> s1;
typedef mpl::copy<
    s1,
    mpl::back_inserter<s0>
>::type concatenated;

BOOST_MPL_ASSERT((
    mpl::equal<
        concatenated,
        mpl::vector<T0, T1, T2, T3>
    >
));


来源:https://stackoverflow.com/questions/19575018/how-to-concatenate-boostmplvectors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!