tmp/tmpg244ecq1/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### Matching of partial specializations <a id="temp.spec.partial.match">[[temp.spec.partial.match]]</a>
|
| 2 |
+
|
| 3 |
+
When a template is used in a context that requires an instantiation of
|
| 4 |
+
the template, it is necessary to determine whether the instantiation is
|
| 5 |
+
to be generated using the primary template or one of the partial
|
| 6 |
+
specializations. This is done by matching the template arguments of the
|
| 7 |
+
template specialization with the template argument lists of the partial
|
| 8 |
+
specializations.
|
| 9 |
+
|
| 10 |
+
- If exactly one matching partial specialization is found, the
|
| 11 |
+
instantiation is generated from that partial specialization.
|
| 12 |
+
- If more than one matching partial specialization is found, the partial
|
| 13 |
+
order rules [[temp.spec.partial.order]] are used to determine whether
|
| 14 |
+
one of the partial specializations is more specialized than the
|
| 15 |
+
others. If such a partial specialization exists, the instantiation is
|
| 16 |
+
generated from that partial specialization; otherwise, the use of the
|
| 17 |
+
template is ambiguous and 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 name that refers to a specialization of a class or variable
|
| 80 |
+
template (e.g., `A<int, int, 1>`), the argument list shall match the
|
| 81 |
+
template parameter list of the primary template. The template arguments
|
| 82 |
+
of a partial specialization are deduced from the arguments of the
|
| 83 |
+
primary template.
|
| 84 |
+
|