N4527 14.5.5.1[temp.class.spec.match]
2 A partial specialization matches a given actual template argument list if the template arguments of the partial specialization can be deduced from the actual template argument list.
template<class T1, class T2, int I> class A { }; // #1 template<class T, int I> class A<T, T*, I> { }; // #2 template<class T1, class T2, int I> class A<T1*, T2, I> { }; // #3 template<class T> class A<int, T*, 5> { }; // #4 template<class T1, class T2, int I> class A<T1, T2*, I> { }; // #5 A<int, int, 1> a1; // uses #1 A<int, int*, 1> a2; // uses #2, T is int, I is 1 A<int, char*, 5> a3; // uses #4, T is char A<int, char*, 1> a4; // uses #5, T1 is int, T2 is char, I is 1 A<int*, int*, 2> a5; // ambiguous: matches #3 and #5
3 A non-type template argument can also be deduced from the value of an actual template argument of a non-type parameter of the primary template. [ Example: the declaration of
a2
above. —end example ]4 In a type name that refers to a class template specialization, (e.g.,
A<int, int, 1>
) the argument list shall match the template parameter list of the primary template. The template arguments of a specialization are deduced from the arguments of the primary template.
In rule3, the example shows I
is deduced from the third actual template argument 1
, this is what the rule2 says. So as the second sentence of rule4, I think it is repeating what rule2 says.
What are the differences between them(rule2, rule3 and rule4)?
Another words, we already have rule2, what are the intents(meaning) of rule3 and the second sentence of rule4, why they are here?
A<int,1> a2
is wrong. For the second sentance, I don't know the difference between it and rule 2. – stackcppA<int, int*, 1> a2;
A<int, int*, 1>
as A,A<T1, T2, I>
as P. – stackcpp