使用提升的模板实例化:传递额外的参数
template instantiation with boost: pass extra arguments
>说我有表单的实例化
template void MyClass<2,typeA>::some_method() const;
用于模板参数的各种组合。
我正在尝试定义一个带有 boost 的宏,它将采用前缀 ( void
( 和一个后缀some_method() const
以便我可以重用它来显式实例化。
使用硬编码的返回类型和函数名称,可以按以下行完成此操作(尚未测试(:
#define DIM (2)(3)
#define DEG (typeA)(typeB)
#define INSTANTIATEONE(_, targs) void MyClass<BOOST_PP_SEQ_ENUM(targs)>::some_method() const;
#define INSTANTIATEALL() BOOST_PP_SEQ_FOR_EACH_PRODUCT(INSTANTIATEONE, (DIM)(DEG));
有没有办法扩展宏以void
和some_method() const
作为参数?我是提升预处理器的新手,不知道该怎么做。
我最终使用
# include <boost/preprocessor/facilities/empty.hpp>
# include <boost/preprocessor/list/at.hpp>
# include <boost/preprocessor/list/for_each_product.hpp>
# include <boost/preprocessor/tuple/elem.hpp>
# include <boost/preprocessor/tuple/to_list.hpp>
#define DIM BOOST_PP_TUPLE_TO_LIST(2,(2,3))
#define DEG BOOST_PP_TUPLE_TO_LIST(1,(typeA))
#define INSTANTIATE(R, L)
template void MyClass<BOOST_PP_TUPLE_ELEM(2, 0, L),
BOOST_PP_TUPLE_ELEM(2, 1, L)>::some_method() const;
BOOST_PP_LIST_FOR_EACH_PRODUCT(INSTANTIATE, 2, (DIM, DEG))
相关文章:
- 在 c++ 中的模板实例化中使用带有构造函数的类作为类型参数
- 如果模板参数是另一个模板的实例化,则键入特征测试
- 如何在模板函数中实例化其长度使用模板参数的数组
- 函数在可变参数模板的实例化期间不可见
- 实例化模板时,我是否必须显式显示参数包中的类型?
- 从模板参数包实例化的访问类实现
- C++ 可变参数模板实例化深度超过最大值 900
- 与参数匹配的友元模板函数实例化
- 有没有办法根据命令行参数定义数组大小?运行时与编译时实例化?
- 在编译时检查未实例化的类模板是否继承自其第一个模板参数
- 如何将包装作为模板参数实例化专用模板类
- 如何在 c++ 中使用枚举参数实例化对象
- 使用NULL参数实例化模板类
- 使用模板参数实例化模板类
- 使用bool非类型参数实例化类模板时出错
- 从类别上防止或阻止使用特定参数实例化对象
- 如何用不同的参数实例化类
- 模板是否为相同类型的参数实例化多次
- C++:根据一个参数实例化一个模板化的类
- 用Constructor参数实例化类对象和不带参数C++的*运算符之间的区别