tmp/tmpkpxx6omr/{from.md → to.md}
RENAMED
|
@@ -27,33 +27,12 @@ appertain to an explicit instantiation.
|
|
| 27 |
If the explicit instantiation is for a class or member class, the
|
| 28 |
*elaborated-type-specifier* in the *declaration* shall include a
|
| 29 |
*simple-template-id*; otherwise, the *declaration* shall be a
|
| 30 |
*simple-declaration* whose *init-declarator-list* comprises a single
|
| 31 |
*init-declarator* that does not have an *initializer*. If the explicit
|
| 32 |
-
instantiation is for a
|
| 33 |
-
in the *declarator* shall be
|
| 34 |
-
template arguments can be deduced, a *template-name* or
|
| 35 |
-
*operator-function-id*.
|
| 36 |
-
|
| 37 |
-
[*Note 1*: The declaration may declare a *qualified-id*, in which case
|
| 38 |
-
the *unqualified-id* of the *qualified-id* must be a
|
| 39 |
-
*template-id*. — *end note*]
|
| 40 |
-
|
| 41 |
-
If the explicit instantiation is for a member function, a member class
|
| 42 |
-
or a static data member of a class template specialization, the name of
|
| 43 |
-
the class template specialization in the *qualified-id* for the member
|
| 44 |
-
name shall be a *simple-template-id*. If the explicit instantiation is
|
| 45 |
-
for a variable template specialization, the *unqualified-id* in the
|
| 46 |
-
*declarator* shall be a *simple-template-id*. An explicit instantiation
|
| 47 |
-
shall appear in an enclosing namespace of its template. If the name
|
| 48 |
-
declared in the explicit instantiation is an unqualified name, the
|
| 49 |
-
explicit instantiation shall appear in the namespace where its template
|
| 50 |
-
is declared or, if that namespace is inline [[namespace.def]], any
|
| 51 |
-
namespace from its enclosing namespace set.
|
| 52 |
-
|
| 53 |
-
[*Note 2*: Regarding qualified names in declarators, see
|
| 54 |
-
[[dcl.meaning]]. — *end note*]
|
| 55 |
|
| 56 |
[*Example 1*:
|
| 57 |
|
| 58 |
``` cpp
|
| 59 |
template<class T> class Array { void mf(); };
|
|
@@ -69,26 +48,28 @@ namespace N {
|
|
| 69 |
template void N::f<int>(int&);
|
| 70 |
```
|
| 71 |
|
| 72 |
— *end example*]
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
template
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
class template
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
|
| 85 |
The *declaration* in an *explicit-instantiation* and the *declaration*
|
| 86 |
produced by the corresponding substitution into the templated function,
|
| 87 |
variable, or class are two declarations of the same entity.
|
| 88 |
|
| 89 |
-
[*Note
|
| 90 |
|
| 91 |
These declarations are required to have matching types as specified in
|
| 92 |
[[basic.link]], except as specified in [[except.spec]].
|
| 93 |
|
| 94 |
[*Example 2*:
|
|
@@ -122,41 +103,17 @@ that template, the explicit instantiation has no effect. Otherwise, for
|
|
| 122 |
an explicit instantiation definition, the definition of a function
|
| 123 |
template, a variable template, a member function template, or a member
|
| 124 |
function or static data member of a class template shall be present in
|
| 125 |
every translation unit in which it is explicitly instantiated.
|
| 126 |
|
| 127 |
-
An explicit instantiation of a class, function template, or variable
|
| 128 |
-
template specialization is placed in the namespace in which the template
|
| 129 |
-
is defined. An explicit instantiation for a member of a class template
|
| 130 |
-
is placed in the namespace where the enclosing class template is
|
| 131 |
-
defined. An explicit instantiation for a member template is placed in
|
| 132 |
-
the namespace where the enclosing class or class template is defined.
|
| 133 |
-
|
| 134 |
-
[*Example 3*:
|
| 135 |
-
|
| 136 |
-
``` cpp
|
| 137 |
-
namespace N {
|
| 138 |
-
template<class T> class Y { void mf() { } };
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
template class Y<int>; // error: class template Y not visible in the global namespace
|
| 142 |
-
|
| 143 |
-
using N::Y;
|
| 144 |
-
template class Y<int>; // error: explicit instantiation outside of the namespace of the template
|
| 145 |
-
|
| 146 |
-
template class N::Y<char*>; // OK: explicit instantiation in namespace N
|
| 147 |
-
template void N::Y<double>::mf(); // OK: explicit instantiation in namespace N
|
| 148 |
-
```
|
| 149 |
-
|
| 150 |
-
— *end example*]
|
| 151 |
-
|
| 152 |
A trailing *template-argument* can be left unspecified in an explicit
|
| 153 |
instantiation of a function template specialization or of a member
|
| 154 |
-
function template specialization provided it can be deduced
|
| 155 |
-
|
|
|
|
| 156 |
|
| 157 |
-
[*Example
|
| 158 |
|
| 159 |
``` cpp
|
| 160 |
template<class T> class Array { ... };
|
| 161 |
template<class T> void sort(Array<T>& v) { ... }
|
| 162 |
|
|
@@ -164,50 +121,49 @@ template<class T> void sort(Array<T>& v) { ... }
|
|
| 164 |
template void sort<>(Array<int>&);
|
| 165 |
```
|
| 166 |
|
| 167 |
— *end example*]
|
| 168 |
|
| 169 |
-
[*Note
|
| 170 |
required to satisfy that template’s associated constraints
|
| 171 |
[[temp.constr.decl]]. The satisfaction of constraints is determined when
|
| 172 |
forming the template name of an explicit instantiation in which all
|
| 173 |
template arguments are specified [[temp.names]], or, for explicit
|
| 174 |
instantiations of function templates, during template argument deduction
|
| 175 |
[[temp.deduct.decl]] when one or more trailing template arguments are
|
| 176 |
left unspecified. — *end note*]
|
| 177 |
|
| 178 |
An explicit instantiation that names a class template specialization is
|
| 179 |
also an explicit instantiation of the same kind (declaration or
|
| 180 |
-
definition) of each of its
|
| 181 |
-
base classes and members that are templates) that has not been
|
| 182 |
previously explicitly specialized in the translation unit containing the
|
| 183 |
explicit instantiation, provided that the associated constraints, if
|
| 184 |
any, of that member are satisfied by the template arguments of the
|
| 185 |
-
explicit instantiation
|
| 186 |
except as described below.
|
| 187 |
|
| 188 |
-
[*Note
|
| 189 |
of certain implementation-dependent data about the class. — *end note*]
|
| 190 |
|
| 191 |
An explicit instantiation definition that names a class template
|
| 192 |
specialization explicitly instantiates the class template specialization
|
| 193 |
and is an explicit instantiation definition of only those members that
|
| 194 |
have been defined at the point of instantiation.
|
| 195 |
|
| 196 |
An explicit instantiation of a prospective destructor [[class.dtor]]
|
| 197 |
-
shall
|
| 198 |
|
| 199 |
If an entity is the subject of both an explicit instantiation
|
| 200 |
declaration and an explicit instantiation definition in the same
|
| 201 |
translation unit, the definition shall follow the declaration. An entity
|
| 202 |
that is the subject of an explicit instantiation declaration and that is
|
| 203 |
also used in a way that would otherwise cause an implicit instantiation
|
| 204 |
[[temp.inst]] in the translation unit shall be the subject of an
|
| 205 |
explicit instantiation definition somewhere in the program; otherwise
|
| 206 |
the program is ill-formed, no diagnostic required.
|
| 207 |
|
| 208 |
-
[*Note
|
| 209 |
explicit instantiation declaration of such an entity has no other
|
| 210 |
normative effect. This is needed to ensure that if the address of an
|
| 211 |
inline function is taken in a translation unit in which the
|
| 212 |
implementation chose to suppress the out-of-line body, another
|
| 213 |
translation unit will supply the body. — *end note*]
|
|
@@ -216,11 +172,11 @@ An explicit instantiation declaration shall not name a specialization of
|
|
| 216 |
a template with internal linkage.
|
| 217 |
|
| 218 |
An explicit instantiation does not constitute a use of a default
|
| 219 |
argument, so default argument instantiation is not done.
|
| 220 |
|
| 221 |
-
[*Example
|
| 222 |
|
| 223 |
``` cpp
|
| 224 |
char* p = 0;
|
| 225 |
template<class T> T g(T x = &p) { return x; }
|
| 226 |
template int g<int>(int); // OK even though &p isn't an int.
|
|
|
|
| 27 |
If the explicit instantiation is for a class or member class, the
|
| 28 |
*elaborated-type-specifier* in the *declaration* shall include a
|
| 29 |
*simple-template-id*; otherwise, the *declaration* shall be a
|
| 30 |
*simple-declaration* whose *init-declarator-list* comprises a single
|
| 31 |
*init-declarator* that does not have an *initializer*. If the explicit
|
| 32 |
+
instantiation is for a variable template specialization, the
|
| 33 |
+
*unqualified-id* in the *declarator* shall be a *simple-template-id*.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
[*Example 1*:
|
| 36 |
|
| 37 |
``` cpp
|
| 38 |
template<class T> class Array { void mf(); };
|
|
|
|
| 48 |
template void N::f<int>(int&);
|
| 49 |
```
|
| 50 |
|
| 51 |
— *end example*]
|
| 52 |
|
| 53 |
+
An explicit instantiation does not introduce a name
|
| 54 |
+
[[basic.scope.scope]]. A declaration of a function template, a variable
|
| 55 |
+
template, a member function or static data member of a class template,
|
| 56 |
+
or a member function template of a class or class template shall be
|
| 57 |
+
reachable from any explicit instantiation of that entity. A definition
|
| 58 |
+
of a class template, a member class of a class template, or a member
|
| 59 |
+
class template of a class or class template shall be reachable from any
|
| 60 |
+
explicit instantiation of that entity unless an explicit specialization
|
| 61 |
+
of the entity with the same template arguments is reachable therefrom.
|
| 62 |
+
If the *declaration* of the explicit instantiation names an
|
| 63 |
+
implicitly-declared special member function [[special]], the program is
|
| 64 |
+
ill-formed.
|
| 65 |
|
| 66 |
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 are required to have matching types as specified in
|
| 73 |
[[basic.link]], except as specified in [[except.spec]].
|
| 74 |
|
| 75 |
[*Example 2*:
|
|
|
|
| 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 |
A trailing *template-argument* can be left unspecified in an explicit
|
| 109 |
instantiation of a function template specialization or of a member
|
| 110 |
+
function template specialization provided it can be deduced
|
| 111 |
+
[[temp.deduct.decl]]. If all template arguments can be deduced, the
|
| 112 |
+
empty template argument list `<>` may be omitted.
|
| 113 |
|
| 114 |
+
[*Example 3*:
|
| 115 |
|
| 116 |
``` cpp
|
| 117 |
template<class T> class Array { ... };
|
| 118 |
template<class T> void sort(Array<T>& v) { ... }
|
| 119 |
|
|
|
|
| 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
|
| 139 |
explicit instantiation, provided that the associated constraints, if
|
| 140 |
any, of that member are satisfied by the template arguments of the
|
| 141 |
+
explicit instantiation [[temp.constr.decl]], [[temp.constr.constr]],
|
| 142 |
except as described below.
|
| 143 |
|
| 144 |
+
[*Note 3*: In addition, it will typically be an explicit instantiation
|
| 145 |
of certain implementation-dependent data about the class. — *end note*]
|
| 146 |
|
| 147 |
An explicit instantiation definition that names a class template
|
| 148 |
specialization explicitly instantiates the class template specialization
|
| 149 |
and is an explicit instantiation definition of only those members that
|
| 150 |
have been defined at the point of instantiation.
|
| 151 |
|
| 152 |
An explicit instantiation of a prospective destructor [[class.dtor]]
|
| 153 |
+
shall correspond to the selected destructor of the class.
|
| 154 |
|
| 155 |
If an entity is the subject of both an explicit instantiation
|
| 156 |
declaration and an explicit instantiation definition in the same
|
| 157 |
translation unit, the definition shall follow the declaration. An entity
|
| 158 |
that is the subject of an explicit instantiation declaration and that is
|
| 159 |
also used in a way that would otherwise cause an implicit instantiation
|
| 160 |
[[temp.inst]] in the translation unit shall be the subject of an
|
| 161 |
explicit instantiation definition somewhere in the program; otherwise
|
| 162 |
the program is ill-formed, no diagnostic required.
|
| 163 |
|
| 164 |
+
[*Note 4*: This rule does apply to inline functions even though an
|
| 165 |
explicit instantiation declaration of such an entity has no other
|
| 166 |
normative effect. This is needed to ensure that if the address of an
|
| 167 |
inline function is taken in a translation unit in which the
|
| 168 |
implementation chose to suppress the out-of-line body, another
|
| 169 |
translation unit will supply the body. — *end note*]
|
|
|
|
| 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 4*:
|
| 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.
|