使用 boost 的模板实例化:传递额外的参数

template instantiation with boost: pass extra arguments

说我有表单的实例化

template void MyClass<2,typeA>::some_method() const;

模板参数的各种组合。

我正在尝试使用 boost 定义一个宏,它带有一个前缀 (void) 和一个后缀 some_method() const,以便我可以将它重新用于显式实例化。

使用硬编码的 return 类型和函数名称,可以按照以下方式完成(尚未测试):

#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));

有没有办法扩展宏以将 voidsome_method() const 作为参数?我是 boost 预处理器的新手,不知道该怎么做。

我最终使用了

# 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))