Boost MPL模板列表
Boost MPL list of templates
我想取一个类模板的列表, T1, T2,…TN并有一个类的MPL列表,其中每个模板都使用相同的参数实例化。
boost::mpl::list
不能与模板模板参数列表一起使用,只能使用常规类型参数。
所以下面的代码不起作用:
class A { ... };
template<template <class> class T>
struct ApplyParameterA
{
typedef T<A> Type;
}
typedef boost::mpl::transform<
boost::mpl::list<
T1, T2, T3, T4, ...
>,
ApplyParameterA<boost::mpl::_1>::Type
> TypeList;
我怎样才能使它工作?
您想要这样的内容:
#include <boost/mpl/list.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/assert.hpp>
using namespace boost::mpl;
template< typename U > class T1 {};
template< typename U > class T2 {};
template< typename U > class T3 {};
class MyClass;
typedef transform<
list< T1<_1>, T2<_1>, T3<_1> >
, apply1<_1,MyClass>
>::type r;
BOOST_MPL_ASSERT(( equal< r, list<T1<MyClass>,T2<MyClass>,T3<MyClass> > ));
我想你想要这个:
#include <boost/mpl/list.hpp>
#include <boost/mpl/transform.hpp>
using namespace boost;
using mpl::_1;
template<typename T>
struct Test {};
struct T1 {};
struct T2 {};
struct T3 {};
struct T4 {};
template<template <class> class T>
struct ApplyParameterA
{
template<typename A>
struct apply
{
typedef T<A> type;
};
};
typedef mpl::transform<
mpl::list<T1, T2, T3, T4>,
mpl::apply1<ApplyParameterA<Test>, _1>
> TypeList;
这将使
mpl::list<Test<T1>, Test<T2>, Test<T3>, Test<T4>>
在TypeList 相关文章:
- Pybind11:将元组列表从Python传递到C++
- 从链接列表c++中删除一个项目
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- C++如何通过用户输入删除列表元素
- 读取文件的最后一行并输入到链接列表时出错
- 复制列表初始化的隐式转换的等级是多少
- LNK2038、MSVS2017 MAGMA的原因列表
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 没有为自己的结构调用列表推回方法
- 使用简单类型列表实现的指数编译时间.为什么
- 从push_front操作中获取常规 MPL 列表
- Boost mpl列表和auto_test_case_template编译错误
- 为boost mpl列表中的每种类型继承容器
- 从 boost::mpl:vector 类型列表中定义成员变量
- 如何将 MPL 类型列表折叠到可变参数容器中
- boost::mpl:如何为超过 50 个条目的列表生成预生成的头文件
- 如何遍历非默认构造类的提升 MPL 列表
- 使用 MPL 列表扩展提升变体
- Boost::mpl类型列表函数应用程序
- Boost MPL模板列表