I am scratching my head with a strange problem highlighted by the following minimal code:
struct A {
template <typename ...X, typename ...Y>
void f(X... a, Y...b) {
}
template <typename ...X>
void g(X...c) {
f<X...> (c...);
}
};
template <typename T>
struct B {
template <typename ...X, typename ...Y>
void f(X... a, Y...b) {
}
template <typename ...X>
void g(X...c) {
f<X...> (c...);
}
};
int main() {
A a;
a.g(); // Compiles without problem
B<int> b;
b.g(); // Compiler complains saying g() calls f<>() with 0 arguments while 1 is expected
}
Both g++ and clang++ give the same basic error messages for the second case. They basically say that the call to f() within the templated class needs one argument.
Is this a bug in both compilers, or am I missing something in the C++ standard?
The method taking two parameter packs is illegal according to 14.1 [temp.param] paragraph 11:
... A template parameter pack of a function template shall not be followed by another template parameter unless that template parameter can be deduced from the parameter-type-list of the function template or has a default argument (14.8.2). [ Example:
template<class T1 = int, class T2> class B; // error
// U cannot be neither deduced from the parameter-type-list nor specified
template<class... T, class... U> void f() { } // error
template<class... T, class U> void g() { } // error
—end example ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With