2

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

fusion::pair< mpl::int_< VALUE >, 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;

这编译并产生了预期的结果,不幸的是,如果我尝试包装对转换的调用,我会收到大量错误。IE:

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;

编译器错误如下:

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

我的to_vector_of_fusion_pair结构有什么问题使其与 不兼容mpl::transform

4

1 回答 1

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

阅读此内容以获得解释我必须在何处以及为什么必须放置“模板”和“类型名称”关键字?

于 2012-10-29T11:46:24.140 回答