1
如果我有一个类型列表,我怎样才能得到一个类型的列表,因为它是可变参数?如何将MPL类型列表折叠到可变参数容器中?
换句话说,我想从这个去:
boost::mpl::list<foo, bar, baz, quux>
要:
types<foo, bar, baz, quux>
(顺序并不重要)
下面是使用fold
我尝试:
typedef boost::mpl::list<foo, bar, baz, quux> type_list;
template <typename... Ts>
struct types {};
template <template <typename... Ts> class List, typename T>
struct add_to_types {
typedef types<T, typename Ts...> type;
};
typedef boost::mpl::fold<
type_list,
types<>,
add_to_types<boost::mpl::_1, boost::mpl::_2>
>::type final_type;
不幸的是这给了我错误关于占位符:
error: type/value mismatch at argument 1 in template parameter list for 'template<template<class ... Ts> class List, class T> struct add_to_types'
error: expected a class template, got 'mpl_::_1 {aka mpl_::arg<1>}'
error: template argument 3 is invalid
error: expected initializer before 'final_type'
辉煌,工作就像一个魅力! –