C++ 如何在折叠期间获取boost::mpl占位符的成员类型
假设有两类:C++ 如何在折叠期间获取boost::mpl占位符的成员类型,c++,metaprogramming,boost-mpl,boost-fusion,C++,Metaprogramming,Boost Mpl,Boost Fusion,假设有两类: struct A { using Key = int; using Value = char; }; struct B { using Key = char; using Value = float; }; 我想使用它们的成员类型来定义融合映射: typedef boost::fusion::map < boost::fusion::pair< int , char > , boost::fusion::pair
struct A
{
using Key = int;
using Value = char;
};
struct B
{
using Key = char;
using Value = float;
};
我想使用它们的成员类型来定义融合映射:
typedef boost::fusion::map
<
boost::fusion::pair< int , char > ,
boost::fusion::pair< char , float >
> desired_type;
并正确定义了折叠:
typedef boost::fusion::result_of::as_map< boost::mpl::fold
<
boost::mpl::vector< A , B > ,
boost::fusion::map< > ,
boost::fusion::result_of::push_back
<
boost::mpl::_1 ,
boost::fusion::result_of::make_pair
<
GetInnerKey< boost::mpl::_2 > , GetInnerValue< boost::mpl::_2 >
>
>
>::type >::type map_type;
typedef boost::fusion::result_of::as_map,
boost::fusion::map<>,
boost::fusion::结果\的::推回
<
boost::mpl::_1,
boost::fusion::result\u of::make\u pair
<
GetInnerKey,GetInnerValue
>
>
>::type>::type map\u type;
()
我的问题是:
- 有没有一种方法可以使用MPL或Fusion中已经定义的内容来摆脱
和GetInnerKey<>
GetInnerValue<>
- 有没有办法避免使用
boost::fusion::result\u of::as\u map<>
- 这是实现我意图的正确方法吗
模板
结构映射类型
{
typedef typename映射类型::type pts\u映射;
typedef typename boost::fusion::result_of::as_map<
boost::fusion::联合视图<
boost::fusion::map<
boost::fusion::pair
>,
pts_地图
>
>::类型类型;
};
模板
结构映射类型
{
typedef boost::fusion::map<
boost::fusion::pair
>类型;
};
template< class T >
struct GetInnerKey
{
typedef typename T::Key type;
};
template< class T >
struct GetInnerValue
{
typedef typename T::Value type;
};
typedef boost::fusion::result_of::as_map< boost::mpl::fold
<
boost::mpl::vector< A , B > ,
boost::fusion::map< > ,
boost::fusion::result_of::push_back
<
boost::mpl::_1 ,
boost::fusion::result_of::make_pair
<
GetInnerKey< boost::mpl::_2 > , GetInnerValue< boost::mpl::_2 >
>
>
>::type >::type map_type;
template <class PT1, class... PTs>
struct map_type
{
typedef typename map_type<PTs...>::type pts_map;
typedef typename boost::fusion::result_of::as_map<
boost::fusion::joint_view<
boost::fusion::map<
boost::fusion::pair< typename PT1::Key, typename PT1::Value>
>,
pts_map
>
>::type type;
};
template <class PT1>
struct map_type<PT1>
{
typedef boost::fusion::map<
boost::fusion::pair< typename PT1::Key, typename PT1::Value>
> type;
};