函数one()接受一个参数包.函数二()接受两个.每个包都被约束为包裹在类型A和B中.为什么不可能实例化两个()?
template <typename T>
struct A {};
template <typename T>
struct B {};
template <typename... Ts>
void one(A<Ts> ...as) {
}
template <typename... Ts, typename... Us>
void two(A<Ts> ...as, B<Us> ...bs) {
}
int main() {
auto a = A<int>();
auto b = B<int>();
// Just fine
one();
one(a);
one(a, a);
// All errors
two();
two(a);
two(a, b);
}
Run Code Online (Sandbox Code Playgroud)
试过gcc和clang.
sam@wish:~/x/cpp$ gcc -std=c++0x variadic_templates.cpp
variadic_templates.cpp: In function ‘int main()’:
variadic_templates.cpp:23:7: …Run Code Online (Sandbox Code Playgroud)