【发布时间】:2017-07-16 16:24:24
【问题描述】:
我有一个类Foo,它需要有可变数量的模板参数,但这些参数需要是某种通用类型,而不是完全任意的。例如
template < int I, typename T> struct Arg;
using type1 = Foo<Arg<3, double>>;
using type2 = Foo<Arg<1, int>, Arg<7, float>, Arg<1, int>>;
我想知道实现这一目标的最佳方法是什么。我想我需要先从一个普通的可变参数模板开始
template < typename ...T >
class Foo;
从那里,我可以沿着递归的道路前进
template < int I, typename T, typename ...Others>
template Foo<Arg<I, T>, Others...>
{
...
};
但是阅读this answer 到另一个问题让我想知道我对可变参数模板的了解以及有时如何避免递归。
我的问题是,模板参数预计采用相对严格的格式这一事实是否能够实现Foo 的部分特化,它不会是递归的,并且可以有效地处理所有Foos 形式Foo<Arg<...>,Arg<...>,...>?
【问题讨论】: