From Jason Turner

[temp.class.spec.match]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp88gvwddi/{from.md → to.md} +0 -83
tmp/tmp88gvwddi/{from.md → to.md} RENAMED
@@ -1,83 +0,0 @@
1
- #### Matching of class template partial specializations <a id="temp.class.spec.match">[[temp.class.spec.match]]</a>
2
-
3
- When a class template is used in a context that requires an
4
- instantiation of the class, it is necessary to determine whether the
5
- instantiation is to be generated using the primary template or one of
6
- the partial specializations. This is done by matching the template
7
- arguments of the class template specialization with the template
8
- argument lists of the partial specializations.
9
-
10
- - If exactly one matching specialization is found, the instantiation is
11
- generated from that specialization.
12
- - If more than one matching specialization is found, the partial order
13
- rules [[temp.class.order]] are used to determine whether one of the
14
- specializations is more specialized than the others. If none of the
15
- specializations is more specialized than all of the other matching
16
- specializations, then the use of the class template is ambiguous and
17
- the program is ill-formed.
18
- - If no matches are found, the instantiation is generated from the
19
- primary template.
20
-
21
- A partial specialization matches a given actual template argument list
22
- if the template arguments of the partial specialization can be deduced
23
- from the actual template argument list [[temp.deduct]], and the deduced
24
- template arguments satisfy the associated constraints of the partial
25
- specialization, if any [[temp.constr.decl]].
26
-
27
- [*Example 1*:
28
-
29
- ``` cpp
30
- template<class T1, class T2, int I> class A { }; // #1
31
- template<class T, int I> class A<T, T*, I> { }; // #2
32
- template<class T1, class T2, int I> class A<T1*, T2, I> { }; // #3
33
- template<class T> class A<int, T*, 5> { }; // #4
34
- template<class T1, class T2, int I> class A<T1, T2*, I> { }; // #5
35
-
36
- A<int, int, 1> a1; // uses #1
37
- A<int, int*, 1> a2; // uses #2, T is int, I is 1
38
- A<int, char*, 5> a3; // uses #4, T is char
39
- A<int, char*, 1> a4; // uses #5, T1 is int, T2 is char, I is 1
40
- A<int*, int*, 2> a5; // ambiguous: matches #3 and #5
41
- ```
42
-
43
- — *end example*]
44
-
45
- [*Example 2*:
46
-
47
- ``` cpp
48
- template<typename T> concept C = requires (T t) { t.f(); };
49
-
50
- template<typename T> struct S { }; // #1
51
- template<C T> struct S<T> { }; // #2
52
-
53
- struct Arg { void f(); };
54
-
55
- S<int> s1; // uses #1; the constraints of #2 are not satisfied
56
- S<Arg> s2; // uses #2; both constraints are satisfied but #2 is more specialized
57
- ```
58
-
59
- — *end example*]
60
-
61
- If the template arguments of a partial specialization cannot be deduced
62
- because of the structure of its *template-parameter-list* and the
63
- *template-id*, the program is ill-formed.
64
-
65
- [*Example 3*:
66
-
67
- ``` cpp
68
- template <int I, int J> struct A {};
69
- template <int I> struct A<I+5, I*2> {}; // error
70
-
71
- template <int I> struct A<I, I> {}; // OK
72
-
73
- template <int I, int J, int K> struct B {};
74
- template <int I> struct B<I, I*2, 2> {}; // OK
75
- ```
76
-
77
- — *end example*]
78
-
79
- In a type name that refers to a class template specialization, (e.g.,
80
- `A<int, int, 1>`) the argument list shall match the template parameter
81
- list of the primary template. The template arguments of a specialization
82
- are deduced from the arguments of the primary template.
83
-