tmp/tmpk3r3mh9d/{from.md → to.md}
RENAMED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
### Explicit instantiation <a id="temp.explicit">[[temp.explicit]]</a>
|
| 2 |
|
| 3 |
-
A class,
|
| 4 |
-
instantiated from its template. A member function, member
|
| 5 |
-
static data member of a class template can be explicitly
|
| 6 |
-
from the member definition associated with its class
|
| 7 |
-
explicit instantiation of a function template or member
|
| 8 |
-
class template shall not use the `inline` or `constexpr`
|
|
|
|
| 9 |
|
| 10 |
The syntax for explicit instantiation is:
|
| 11 |
|
| 12 |
``` bnf
|
| 13 |
explicit-instantiation:
|
|
@@ -27,17 +28,18 @@ a *template-name* or *operator-function-id*. The declaration may declare
|
|
| 27 |
a *qualified-id*, in which case the *unqualified-id* of the
|
| 28 |
*qualified-id* must be a *template-id*. If the explicit instantiation is
|
| 29 |
for a member function, a member class or a static data member of a class
|
| 30 |
template specialization, the name of the class template specialization
|
| 31 |
in the *qualified-id* for the member name shall be a
|
| 32 |
-
*simple-template-id*.
|
| 33 |
-
|
| 34 |
-
explicit instantiation
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
namespace
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
``` cpp
|
| 41 |
template<class T> class Array { void mf(); };
|
| 42 |
template class Array<char>;
|
| 43 |
template void Array<int>::mf();
|
|
@@ -49,35 +51,36 @@ namespace N {
|
|
| 49 |
template<class T> void f(T&) { }
|
| 50 |
}
|
| 51 |
template void N::f<int>(int&);
|
| 52 |
```
|
| 53 |
|
| 54 |
-
A declaration of a function template, a
|
| 55 |
-
member of a class template, or a member function
|
| 56 |
-
class template shall precede an explicit
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
explicit instantiation of that entity
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
names an implicitly-declared
|
| 63 |
-
[[special]]), the program is
|
|
|
|
| 64 |
|
| 65 |
For a given set of template arguments, if an explicit instantiation of a
|
| 66 |
template appears after a declaration of an explicit specialization for
|
| 67 |
that template, the explicit instantiation has no effect. Otherwise, for
|
| 68 |
an explicit instantiation definition the definition of a function
|
| 69 |
-
template, a
|
| 70 |
-
data member of a class template shall be present in
|
| 71 |
-
unit in which it is explicitly instantiated.
|
| 72 |
|
| 73 |
-
An explicit instantiation of a class
|
| 74 |
-
is placed in the namespace in which the template
|
| 75 |
-
instantiation for a member of a class template
|
| 76 |
-
namespace where the enclosing class template is
|
| 77 |
-
instantiation for a member template is placed in
|
| 78 |
-
enclosing class or class template is defined.
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
namespace N {
|
| 82 |
template<class T> class Y { void mf() { } };
|
| 83 |
}
|
|
@@ -108,28 +111,31 @@ template void sort<>(Array<int>&);
|
|
| 108 |
```
|
| 109 |
|
| 110 |
An explicit instantiation that names a class template specialization is
|
| 111 |
also an explicit instantiation of the same kind (declaration or
|
| 112 |
definition) of each of its members (not including members inherited from
|
| 113 |
-
base classes
|
| 114 |
-
|
| 115 |
-
described below. In addition, it will
|
| 116 |
-
|
|
|
|
| 117 |
|
| 118 |
An explicit instantiation definition that names a class template
|
| 119 |
specialization explicitly instantiates the class template specialization
|
| 120 |
and is an explicit instantiation definition of only those members that
|
| 121 |
have been defined at the point of instantiation.
|
| 122 |
|
| 123 |
-
Except for inline functions
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
the
|
|
|
|
|
|
|
| 131 |
|
| 132 |
If an entity is the subject of both an explicit instantiation
|
| 133 |
declaration and an explicit instantiation definition in the same
|
| 134 |
translation unit, the definition shall follow the declaration. An entity
|
| 135 |
that is the subject of an explicit instantiation declaration and that is
|
|
|
|
| 1 |
### Explicit instantiation <a id="temp.explicit">[[temp.explicit]]</a>
|
| 2 |
|
| 3 |
+
A class, function, variable, or member template specialization can be
|
| 4 |
+
explicitly instantiated from its template. A member function, member
|
| 5 |
+
class or static data member of a class template can be explicitly
|
| 6 |
+
instantiated from the member definition associated with its class
|
| 7 |
+
template. An explicit instantiation of a function template or member
|
| 8 |
+
function of a class template shall not use the `inline` or `constexpr`
|
| 9 |
+
specifiers.
|
| 10 |
|
| 11 |
The syntax for explicit instantiation is:
|
| 12 |
|
| 13 |
``` bnf
|
| 14 |
explicit-instantiation:
|
|
|
|
| 28 |
a *qualified-id*, in which case the *unqualified-id* of the
|
| 29 |
*qualified-id* must be a *template-id*. If the explicit instantiation is
|
| 30 |
for a member function, a member class or a static data member of a class
|
| 31 |
template specialization, the name of the class template specialization
|
| 32 |
in the *qualified-id* for the member name shall be a
|
| 33 |
+
*simple-template-id*. If the explicit instantiation is for a variable,
|
| 34 |
+
the *unqualified-id* in the declaration shall be a *template-id*. An
|
| 35 |
+
explicit instantiation shall appear in an enclosing namespace of its
|
| 36 |
+
template. If the name declared in the explicit instantiation is an
|
| 37 |
+
unqualified name, the explicit instantiation shall appear in the
|
| 38 |
+
namespace where its template is declared or, if that namespace is
|
| 39 |
+
inline ([[namespace.def]]), any namespace from its enclosing namespace
|
| 40 |
+
set. Regarding qualified names in declarators, see [[dcl.meaning]].
|
| 41 |
|
| 42 |
``` cpp
|
| 43 |
template<class T> class Array { void mf(); };
|
| 44 |
template class Array<char>;
|
| 45 |
template void Array<int>::mf();
|
|
|
|
| 51 |
template<class T> void f(T&) { }
|
| 52 |
}
|
| 53 |
template void N::f<int>(int&);
|
| 54 |
```
|
| 55 |
|
| 56 |
+
A declaration of a function template, a variable template, a member
|
| 57 |
+
function or static data member of a class template, or a member function
|
| 58 |
+
template of a class or class template shall precede an explicit
|
| 59 |
+
instantiation of that entity. A definition of a class template, a member
|
| 60 |
+
class of a class template, or a member class template of a class or
|
| 61 |
+
class template shall precede an explicit instantiation of that entity
|
| 62 |
+
unless the explicit instantiation is preceded by an explicit
|
| 63 |
+
specialization of the entity with the same template arguments. If the
|
| 64 |
+
*declaration* of the explicit instantiation names an implicitly-declared
|
| 65 |
+
special member function (Clause [[special]]), the program is
|
| 66 |
+
ill-formed.
|
| 67 |
|
| 68 |
For a given set of template arguments, if an explicit instantiation of a
|
| 69 |
template appears after a declaration of an explicit specialization for
|
| 70 |
that template, the explicit instantiation has no effect. Otherwise, for
|
| 71 |
an explicit instantiation definition the definition of a function
|
| 72 |
+
template, a variable template, a member function template, or a member
|
| 73 |
+
function or static data member of a class template shall be present in
|
| 74 |
+
every translation unit in which it is explicitly instantiated.
|
| 75 |
|
| 76 |
+
An explicit instantiation of a class, function template, or variable
|
| 77 |
+
template specialization is placed in the namespace in which the template
|
| 78 |
+
is defined. An explicit instantiation for a member of a class template
|
| 79 |
+
is placed in the namespace where the enclosing class template is
|
| 80 |
+
defined. An explicit instantiation for a member template is placed in
|
| 81 |
+
the namespace where the enclosing class or class template is defined.
|
| 82 |
|
| 83 |
``` cpp
|
| 84 |
namespace N {
|
| 85 |
template<class T> class Y { void mf() { } };
|
| 86 |
}
|
|
|
|
| 111 |
```
|
| 112 |
|
| 113 |
An explicit instantiation that names a class template specialization is
|
| 114 |
also an explicit instantiation of the same kind (declaration or
|
| 115 |
definition) of each of its members (not including members inherited from
|
| 116 |
+
base classes and members that are templates) that has not been
|
| 117 |
+
previously explicitly specialized in the translation unit containing the
|
| 118 |
+
explicit instantiation, except as described below. In addition, it will
|
| 119 |
+
typically be an explicit instantiation of certain
|
| 120 |
+
implementation-dependent data about the class.
|
| 121 |
|
| 122 |
An explicit instantiation definition that names a class template
|
| 123 |
specialization explicitly instantiates the class template specialization
|
| 124 |
and is an explicit instantiation definition of only those members that
|
| 125 |
have been defined at the point of instantiation.
|
| 126 |
|
| 127 |
+
Except for inline functions, declarations with types deduced from their
|
| 128 |
+
initializer or return value ([[dcl.spec.auto]]), `const` variables of
|
| 129 |
+
literal types, variables of reference types, and class template
|
| 130 |
+
specializations, explicit instantiation declarations have the effect of
|
| 131 |
+
suppressing the implicit instantiation of the entity to which they
|
| 132 |
+
refer. The intent is that an inline function that is the subject of an
|
| 133 |
+
explicit instantiation declaration will still be implicitly instantiated
|
| 134 |
+
when odr-used ([[basic.def.odr]]) so that the body can be considered
|
| 135 |
+
for inlining, but that no out-of-line copy of the inline function would
|
| 136 |
+
be generated in the translation unit.
|
| 137 |
|
| 138 |
If an entity is the subject of both an explicit instantiation
|
| 139 |
declaration and an explicit instantiation definition in the same
|
| 140 |
translation unit, the definition shall follow the declaration. An entity
|
| 141 |
that is the subject of an explicit instantiation declaration and that is
|