【发布时间】:2015-02-18 14:06:26
【问题描述】:
如果我使用 boost::mpl,让我们看看下面的代码:
typedef fold<
vector<long,float,long>
, set0<>
, insert<_1,_2>
>::type s;
BOOST_MPL_ASSERT_RELATION( size<s>::value, ==, 2 );
如何将s 再次转换为t = boost::mpl::set<long,float> 类型,以便我可以使用t 选择提取元素类型的部分专用模板函数(在 boost::mpl::set 上)并将其变成 std::tuple<long,float> 。这是另一回事
【问题讨论】:
-
boost::mpl的设计有点过时,因为它早于 C++11 的可变参数模板和模板别名。使用Eric Niebler's Tiny Meta-Programming Library 等更现代的东西可能会更轻松。例如,template<class...Ts> using unique_tuple = meta::apply_list<meta::quote<std::tuple>, meta::unique<meta::list<Ts...>>>;will computestd::tuple<long, float>fromunique_tuple<long,float,long>。
标签: templates c++11 variadic-templates boost-mpl