从mpl :: vector生成fusion :: vector

And*_*reo 3 c++ templates metaprogramming boost-fusion

如何生成fusion::vectormpl::vector?如何生成mpl::vectorfusion::vector

BOOST_MPL_ASSERT((is_same<
                  fusion::vector<int, char>,
                  generate_fusion_vector<mpl::vector<int, char> >::type >));

BOOST_MPL_ASSERT((is_same<
                  mpl::vector<int, char>,
                  generate_mpl_vector<fusion::vector<int, char> >::type >));
Run Code Online (Sandbox Code Playgroud)

我需要generate_fusion_vectorgenerate_mpl_vector元功能.我可以编写自己的元函数,但我怀疑它们已经存在.

我之前有过使用过fusion::map帮助的经验result_of::as_map,但是在当前的boost(trunk,也是1.39)中会出现这样的错误:

D:\Libraries\boost_trunk\boost/fusion/sequence/intrinsic/size.hpp(56) : error C2903: 'apply' : symbol is neither a class template nor a function template
        D:\Libraries\boost_trunk\boost/fusion/container/vector/convert.hpp(23) : see reference to class template instantiation 'boost::fusion::result_of::size' being compiled
        with
        [
            Sequence=boost::mpl::vector
        ]
        temp.cpp(71) : see reference to class template instantiation 'boost::fusion::result_of::as_vector' being compiled
Run Code Online (Sandbox Code Playgroud)

我不明白发生了什么事?

Mat*_*han 7

由于fusion接受mpl类型作为函数的参数,您可以尝试这样做:

BOOST_MPL_ASSERT((is_same<
fusion::vector<int, char>,
fusion::result_of::as_vector<mpl::vector<int, char> >::type >));
Run Code Online (Sandbox Code Playgroud)

编辑:

我认为这对您不起作用的原因是您必须包含某些头文件以在Fusion中启用mpl兼容性.

#include <boost/fusion/adapted/mpl.hpp>
#include <boost/fusion/include/mpl.hpp>
Run Code Online (Sandbox Code Playgroud)