tmp/tmps6ngu19q/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### General <a id="temp.class.general">[[temp.class.general]]</a>
|
| 2 |
+
|
| 3 |
+
A *class template* defines the layout and operations for an unbounded
|
| 4 |
+
set of related types.
|
| 5 |
+
|
| 6 |
+
[*Example 1*:
|
| 7 |
+
|
| 8 |
+
It is possible for a single class template `List` to provide an
|
| 9 |
+
unbounded set of class definitions: one class `List<T>` for every type
|
| 10 |
+
`T`, each describing a linked list of elements of type `T`. Similarly, a
|
| 11 |
+
class template `Array` describing a contiguous, dynamic array can be
|
| 12 |
+
defined like this:
|
| 13 |
+
|
| 14 |
+
``` cpp
|
| 15 |
+
template<class T> class Array {
|
| 16 |
+
T* v;
|
| 17 |
+
int sz;
|
| 18 |
+
public:
|
| 19 |
+
explicit Array(int);
|
| 20 |
+
T& operator[](int);
|
| 21 |
+
T& elem(int i) { return v[i]; }
|
| 22 |
+
};
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
The prefix `template<class T>` specifies that a template is being
|
| 26 |
+
declared and that a *type-name* `T` can be used in the declaration. In
|
| 27 |
+
other words, `Array` is a parameterized type with `T` as its parameter.
|
| 28 |
+
|
| 29 |
+
— *end example*]
|
| 30 |
+
|
| 31 |
+
[*Note 1*:
|
| 32 |
+
|
| 33 |
+
When a member of a class template is defined outside of the class
|
| 34 |
+
template definition, the member definition is defined as a template
|
| 35 |
+
definition with the *template-head* equivalent to that of the class
|
| 36 |
+
template. The names of the template parameters used in the definition of
|
| 37 |
+
the member can differ from the template parameter names used in the
|
| 38 |
+
class template definition. The class template name in the member
|
| 39 |
+
definition is followed by the template argument list of the
|
| 40 |
+
*template-head* [[temp.arg]].
|
| 41 |
+
|
| 42 |
+
[*Example 2*:
|
| 43 |
+
|
| 44 |
+
``` cpp
|
| 45 |
+
template<class T1, class T2> struct A {
|
| 46 |
+
void f1();
|
| 47 |
+
void f2();
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
template<class T2, class T1> void A<T2,T1>::f1() { } // OK
|
| 51 |
+
template<class T2, class T1> void A<T1,T2>::f2() { } // error
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
``` cpp
|
| 55 |
+
template<class ... Types> struct B {
|
| 56 |
+
void f3();
|
| 57 |
+
void f4();
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
template<class ... Types> void B<Types ...>::f3() { } // OK
|
| 61 |
+
template<class ... Types> void B<Types>::f4() { } // error
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
``` cpp
|
| 65 |
+
template<typename T> concept C = true;
|
| 66 |
+
template<typename T> concept D = true;
|
| 67 |
+
|
| 68 |
+
template<C T> struct S {
|
| 69 |
+
void f();
|
| 70 |
+
void g();
|
| 71 |
+
void h();
|
| 72 |
+
template<D U> struct Inner;
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
template<C A> void S<A>::f() { } // OK, template-head{s} match
|
| 76 |
+
template<typename T> void S<T>::g() { } // error: no matching declaration for S<T>
|
| 77 |
+
|
| 78 |
+
template<typename T> requires C<T> // ill-formed, no diagnostic required: template-head{s} are
|
| 79 |
+
void S<T>::h() { } // functionally equivalent but not equivalent
|
| 80 |
+
|
| 81 |
+
template<C X> template<D Y>
|
| 82 |
+
struct S<X>::Inner { }; // OK
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
— *end example*]
|
| 86 |
+
|
| 87 |
+
— *end note*]
|
| 88 |
+
|
| 89 |
+
In a partial specialization, explicit specialization or explicit
|
| 90 |
+
instantiation of a class template, the *class-key* shall agree in kind
|
| 91 |
+
with the original class template declaration [[dcl.type.elab]].
|
| 92 |
+
|