Reputation: 165
line 1; template <class T, T t> struct C {}; // primary template
line 2: template <class T> struct C<T, 1>; // error: type of the argument 1 is
// which depends on the parameter T
my understanding is that primary template accepts two template arguments which are same type. but in line 2, one parameter is unknown, the second one is int(1), so these two parameters can not be same type in certain cases.
but the error message saying "depend one..." according to https://en.cppreference.com/w/cpp/language/partial_specialization
how should I understand this case?
Another question is
template <class T, T t>
template <class T, T>
is there any difference in behaviour or anything else between these two
thank you for your help
Upvotes: 0
Views: 67
Reputation: 311078
According to the C++ 17 Standard (17.5.5 Class template partial specializations)
8 Within the argument list of a class template partial specialization, the following restrictions apply:
(8.1) — The type of a template parameter corresponding to a specialized non-type argument shall not be dependent on a parameter of the specialization
As for these two template parameter lists
template <class T, T t>
template <class T, T>
then the only difference is that the identifier of the non-type template parameter in the second case is not specified. So within the template definition you can not refer it.
Upvotes: 1