考虑代码:是否合法,以部分地专门与来自外部类的可变参数模板ARGS可变参数模板内部类
#include <iostream>
template <class... Ts>
struct outer {
template <class... ITs>
struct inner {
static constexpr bool value = false;
};
template <class... ITs>
struct inner<Ts..., ITs...> {
static constexpr bool value = true;
};
};
int main() {
std::cout << outer<int, float, double>::inner<int, float, double, int>::value << std::endl;
}
代码编译与铛++但不与克++,它产生一个错误:
temp3.cc:11:11: error: parameter pack argument ‘Ts ...’ must be at the end of the template argument list
struct inner<Ts..., ITs...> { ^
由于我已经建立here内部类的部分专业化应该是合法的。
编辑: 出于完整性很值得补充说,铛上面的代码警告说,他可能会与推断它的参数还没有这样做没有任何问题一个问题...
我完全不知道规则,但是当我得到一个依赖类型的错误时,在它有时帮助之前添加'typename'或'template'。试试'struct inner
Dani
添加'typename'后我得到'temp3.cc:11:39:错误:模板参数1无效' –
请注意,请求的场景仍然可以通过一些额外的模板元编程实现... http:///coliru.stacked-crooked.com/a/0c6c643c8ff5809e(是的,我知道这不是问题,但实施它的挑战是不可避免的...)。 –