Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.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++ 使用mpl::transform生成新序列_C++_Boost Mpl - Fatal编程技术网

C++ 使用mpl::transform生成新序列

C++ 使用mpl::transform生成新序列,c++,boost-mpl,C++,Boost Mpl,我正在尝试生成一些通用配置处理代码,将索引映射到类型,使用内部格式如下的fusion::map: fusion::pair< mpl::int_< VALUE >, type >; fusion-db.cpp:40: error: type boost::mpl::transform<Seq, to_fusion_pair<mpl_::arg<1> >, mpl_::na, mpl_::na> is not derived from

我正在尝试生成一些通用配置处理代码,将索引映射到类型,使用内部格式如下的
fusion::map

fusion::pair< mpl::int_< VALUE >, type >;
fusion-db.cpp:40: error: type boost::mpl::transform<Seq, to_fusion_pair<mpl_::arg<1> >, mpl_::na, mpl_::na> is not derived from type to_vector_of_fusion_pair<Seq>â
fusion-db.cpp:40: error: expected ; before type
fusion::pair,type>;
为了简化地图的生成,我有以下代码:

#include <boost/fusion/sequence.hpp>
#include <boost/fusion/container.hpp>
#include <boost/fusion/algorithm.hpp>

#include <boost/mpl/int.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/map.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/placeholders.hpp>

#include <typeinfo>
#include <string>
#include <iostream>

/// create a fusion map of all parameter data
namespace fusion = boost::fusion;
namespace mpl = boost::mpl;

template < unsigned Idx, typename T >
struct config_param
{
    typedef mpl::int_< Idx > index_value;
    typedef T value_type;
};

template< class T >
struct to_fusion_pair
{
    typedef fusion::pair< typename T::index_value
                        , typename T::value_type > type;
};

typedef mpl::vector< config_param< 10, unsigned >
                   , config_param< 20, std::string >
                   , config_param< 30, bool >
                   , config_param< 40, long >
                   , config_param< 50, std::string >
                   > MySequence;

typedef mpl::transform< MySequence, to_fusion_pair< mpl::_1 > >::type ConvertedSeq;
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
///创建所有参数数据的融合图
名称空间融合=boost::fusion;
名称空间mpl=boost::mpl;
模板
结构配置参数
{
typedef mpl::int_索引_值;
类型定义T值_类型;
};
模板
结构到融合对
{
typedef fusion::pairtype;
};
typedef mpl::vector
,配置参数<20,标准::字符串>
,配置参数<30,布尔>
,配置参数<40,长>
,配置参数<50,标准::字符串>
>顺序;
typedef mpl::transform>:type ConvertedSeq;
这会编译并产生预期的结果,不幸的是,如果我尝试包装对transform的调用,就会出现大量错误。i、 e:

template< class Seq >
struct to_vector_of_fusion_pair
{
    typedef mpl::transform< Seq, to_fusion_pair< mpl::_1 > >::type type;
};

typedef to_vector_of_fusion_pair<MySequence>::type ConvertedSeq2;
模板
结构到融合对的向量
{
typedef mpl::transform>:type type;
};
typedef到_fusion_对的_vector_::type ConvertedSeq2;
编译器错误如下所示:

fusion::pair< mpl::int_< VALUE >, type >;
fusion-db.cpp:40: error: type boost::mpl::transform<Seq, to_fusion_pair<mpl_::arg<1> >, mpl_::na, mpl_::na> is not derived from type to_vector_of_fusion_pair<Seq>â
fusion-db.cpp:40: error: expected ; before type
fusion db.cpp:40:error:type boost::mpl::transform不是从\u fusion\u对的类型到\u向量\u派生的
融合数据库cpp:40:错误:预期;打字前
我的
to\u vector\u of \u fusion\u pair
结构有什么问题,它与
mpl::transform
不兼容?

模板
template< class Seq >
struct to_vector_of_fusion_pair
{
    typedef typename mpl::transform< Seq, to_fusion_pair< mpl::_1 > >::type type;
};
结构到融合对的向量 { typedef typename mpl::transform>:type type; };
请阅读本文以获得解释