I am trying to generate some generic configuration handling code that maps indexes to types, using a fusion::map
with an internal format as follows:
fusion::pair< mpl::int_< VALUE >, type >;
To simplify generation of the map I have the following code:
#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;
This compiles and produces the expected results, unfortunately if I try to wrap the call to transform, I get a large number of errors. 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;
The compiler errors are as follows:
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
What is wrong with my to_vector_of_fusion_pair
structure that makes it incompatible with mpl::transform
?
template< class Seq >
struct to_vector_of_fusion_pair
{
typedef typename mpl::transform< Seq, to_fusion_pair< mpl::_1 > >::type type;
};
Read this for explanations Where and why do I have to put the "template" and "typename" keywords?