tmp/tmp1327cov8/{from.md → to.md}
RENAMED
|
@@ -38,11 +38,11 @@ instantiation is for a variable template specialization, the
|
|
| 38 |
template<class T> class Array { void mf(); };
|
| 39 |
template class Array<char>;
|
| 40 |
template void Array<int>::mf();
|
| 41 |
|
| 42 |
template<class T> void sort(Array<T>& v) { ... }
|
| 43 |
-
template void sort(Array<char>&); // argument is deduced here
|
| 44 |
|
| 45 |
namespace N {
|
| 46 |
template<class T> void f(T&) { }
|
| 47 |
}
|
| 48 |
template void N::f<int>(int&);
|
|
@@ -67,11 +67,11 @@ The *declaration* in an *explicit-instantiation* and the *declaration*
|
|
| 67 |
produced by the corresponding substitution into the templated function,
|
| 68 |
variable, or class are two declarations of the same entity.
|
| 69 |
|
| 70 |
[*Note 1*:
|
| 71 |
|
| 72 |
-
These declarations
|
| 73 |
[[basic.link]], except as specified in [[except.spec]].
|
| 74 |
|
| 75 |
[*Example 2*:
|
| 76 |
|
| 77 |
``` cpp
|
|
@@ -79,11 +79,11 @@ template<typename T> T var = {};
|
|
| 79 |
template float var<float>; // OK, instantiated variable has type float
|
| 80 |
template int var<int[16]>[]; // OK, absence of major array bound is permitted
|
| 81 |
template int *var<int>; // error: instantiated variable has type int
|
| 82 |
|
| 83 |
template<typename T> auto av = T();
|
| 84 |
-
template int av<int>; // OK, variable with type
|
| 85 |
|
| 86 |
template<typename T> auto f() {}
|
| 87 |
template void f<int>(); // error: function with deduced return type
|
| 88 |
// redeclared with non-deduced return type[dcl.spec.auto]
|
| 89 |
```
|
|
@@ -103,36 +103,18 @@ that template, the explicit instantiation has no effect. Otherwise, for
|
|
| 103 |
an explicit instantiation definition, the definition of a function
|
| 104 |
template, a variable template, a member function template, or a member
|
| 105 |
function or static data member of a class template shall be present in
|
| 106 |
every translation unit in which it is explicitly instantiated.
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
``` cpp
|
| 117 |
-
template<class T> class Array { ... };
|
| 118 |
-
template<class T> void sort(Array<T>& v) { ... }
|
| 119 |
-
|
| 120 |
-
// instantiate sort(Array<int>&) -- template-argument deduced
|
| 121 |
-
template void sort<>(Array<int>&);
|
| 122 |
-
```
|
| 123 |
-
|
| 124 |
-
— *end example*]
|
| 125 |
-
|
| 126 |
-
[*Note 2*: An explicit instantiation of a constrained template is
|
| 127 |
-
required to satisfy that template’s associated constraints
|
| 128 |
-
[[temp.constr.decl]]. The satisfaction of constraints is determined when
|
| 129 |
-
forming the template name of an explicit instantiation in which all
|
| 130 |
-
template arguments are specified [[temp.names]], or, for explicit
|
| 131 |
-
instantiations of function templates, during template argument deduction
|
| 132 |
-
[[temp.deduct.decl]] when one or more trailing template arguments are
|
| 133 |
-
left unspecified. — *end note*]
|
| 134 |
|
| 135 |
An explicit instantiation that names a class template specialization is
|
| 136 |
also an explicit instantiation of the same kind (declaration or
|
| 137 |
definition) of each of its direct non-template members that has not been
|
| 138 |
previously explicitly specialized in the translation unit containing the
|
|
@@ -172,11 +154,11 @@ An explicit instantiation declaration shall not name a specialization of
|
|
| 172 |
a template with internal linkage.
|
| 173 |
|
| 174 |
An explicit instantiation does not constitute a use of a default
|
| 175 |
argument, so default argument instantiation is not done.
|
| 176 |
|
| 177 |
-
[*Example
|
| 178 |
|
| 179 |
``` cpp
|
| 180 |
char* p = 0;
|
| 181 |
template<class T> T g(T x = &p) { return x; }
|
| 182 |
template int g<int>(int); // OK even though &p isn't an int.
|
|
|
|
| 38 |
template<class T> class Array { void mf(); };
|
| 39 |
template class Array<char>;
|
| 40 |
template void Array<int>::mf();
|
| 41 |
|
| 42 |
template<class T> void sort(Array<T>& v) { ... }
|
| 43 |
+
template void sort(Array<char>&); // argument is deduced here[temp.arg.explicit]
|
| 44 |
|
| 45 |
namespace N {
|
| 46 |
template<class T> void f(T&) { }
|
| 47 |
}
|
| 48 |
template void N::f<int>(int&);
|
|
|
|
| 67 |
produced by the corresponding substitution into the templated function,
|
| 68 |
variable, or class are two declarations of the same entity.
|
| 69 |
|
| 70 |
[*Note 1*:
|
| 71 |
|
| 72 |
+
These declarations need to have matching types as specified in
|
| 73 |
[[basic.link]], except as specified in [[except.spec]].
|
| 74 |
|
| 75 |
[*Example 2*:
|
| 76 |
|
| 77 |
``` cpp
|
|
|
|
| 79 |
template float var<float>; // OK, instantiated variable has type float
|
| 80 |
template int var<int[16]>[]; // OK, absence of major array bound is permitted
|
| 81 |
template int *var<int>; // error: instantiated variable has type int
|
| 82 |
|
| 83 |
template<typename T> auto av = T();
|
| 84 |
+
template int av<int>; // OK, variable with type auto can be redeclared with type int
|
| 85 |
|
| 86 |
template<typename T> auto f() {}
|
| 87 |
template void f<int>(); // error: function with deduced return type
|
| 88 |
// redeclared with non-deduced return type[dcl.spec.auto]
|
| 89 |
```
|
|
|
|
| 103 |
an explicit instantiation definition, the definition of a function
|
| 104 |
template, a variable template, a member function template, or a member
|
| 105 |
function or static data member of a class template shall be present in
|
| 106 |
every translation unit in which it is explicitly instantiated.
|
| 107 |
|
| 108 |
+
[*Note 2*: An explicit instantiation of a constrained template needs to
|
| 109 |
+
satisfy that template’s associated constraints [[temp.constr.decl]]. The
|
| 110 |
+
satisfaction of constraints is determined when forming the template name
|
| 111 |
+
of an explicit instantiation in which all template arguments are
|
| 112 |
+
specified [[temp.names]], or, for explicit instantiations of function
|
| 113 |
+
templates, during template argument deduction [[temp.deduct.decl]] when
|
| 114 |
+
one or more trailing template arguments are left
|
| 115 |
+
unspecified. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
An explicit instantiation that names a class template specialization is
|
| 118 |
also an explicit instantiation of the same kind (declaration or
|
| 119 |
definition) of each of its direct non-template members that has not been
|
| 120 |
previously explicitly specialized in the translation unit containing the
|
|
|
|
| 154 |
a template with internal linkage.
|
| 155 |
|
| 156 |
An explicit instantiation does not constitute a use of a default
|
| 157 |
argument, so default argument instantiation is not done.
|
| 158 |
|
| 159 |
+
[*Example 3*:
|
| 160 |
|
| 161 |
``` cpp
|
| 162 |
char* p = 0;
|
| 163 |
template<class T> T g(T x = &p) { return x; }
|
| 164 |
template int g<int>(int); // OK even though &p isn't an int.
|