tmp/tmp0roywrht/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### General <a id="temp.spec.general">[[temp.spec.general]]</a>
|
| 2 |
+
|
| 3 |
+
The act of instantiating a function, a variable, a class, a member of a
|
| 4 |
+
class template, or a member template is referred to as *template
|
| 5 |
+
instantiation*.
|
| 6 |
+
|
| 7 |
+
A function instantiated from a function template is called an
|
| 8 |
+
instantiated function. A class instantiated from a class template is
|
| 9 |
+
called an instantiated class. A member function, a member class, a
|
| 10 |
+
member enumeration, or a static data member of a class template
|
| 11 |
+
instantiated from the member definition of the class template is called,
|
| 12 |
+
respectively, an instantiated member function, member class, member
|
| 13 |
+
enumeration, or static data member. A member function instantiated from
|
| 14 |
+
a member function template is called an instantiated member function. A
|
| 15 |
+
member class instantiated from a member class template is called an
|
| 16 |
+
instantiated member class. A variable instantiated from a variable
|
| 17 |
+
template is called an instantiated variable. A static data member
|
| 18 |
+
instantiated from a static data member template is called an
|
| 19 |
+
instantiated static data member.
|
| 20 |
+
|
| 21 |
+
An explicit specialization may be declared for a function template, a
|
| 22 |
+
variable template, a class template, a member of a class template, or a
|
| 23 |
+
member template. An explicit specialization declaration is introduced by
|
| 24 |
+
`template<>`. In an explicit specialization declaration for a variable
|
| 25 |
+
template, a class template, a member of a class template, or a class
|
| 26 |
+
member template, the variable or class that is explicitly specialized
|
| 27 |
+
shall be specified with a *simple-template-id*. In the explicit
|
| 28 |
+
specialization declaration for a function template or a member function
|
| 29 |
+
template, the function or member function explicitly specialized may be
|
| 30 |
+
specified using a *template-id*.
|
| 31 |
+
|
| 32 |
+
[*Example 1*:
|
| 33 |
+
|
| 34 |
+
``` cpp
|
| 35 |
+
template<class T = int> struct A {
|
| 36 |
+
static int x;
|
| 37 |
+
};
|
| 38 |
+
template<class U> void g(U) { }
|
| 39 |
+
|
| 40 |
+
template<> struct A<double> { }; // specialize for T == double
|
| 41 |
+
template<> struct A<> { }; // specialize for T == int
|
| 42 |
+
template<> void g(char) { } // specialize for U == char
|
| 43 |
+
// U is deduced from the parameter type
|
| 44 |
+
template<> void g<int>(int) { } // specialize for U == int
|
| 45 |
+
template<> int A<char>::x = 0; // specialize for T == char
|
| 46 |
+
|
| 47 |
+
template<class T = int> struct B {
|
| 48 |
+
static int x;
|
| 49 |
+
};
|
| 50 |
+
template<> int B<>::x = 1; // specialize for T == int
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
— *end example*]
|
| 54 |
+
|
| 55 |
+
An instantiated template specialization can be either implicitly
|
| 56 |
+
instantiated [[temp.inst]] for a given argument list or be explicitly
|
| 57 |
+
instantiated [[temp.explicit]]. A *specialization* is a class, variable,
|
| 58 |
+
function, or class member that is either instantiated [[temp.inst]] from
|
| 59 |
+
a templated entity or is an explicit specialization [[temp.expl.spec]]
|
| 60 |
+
of a templated entity.
|
| 61 |
+
|
| 62 |
+
For a given template and a given set of *template-argument*s,
|
| 63 |
+
|
| 64 |
+
- an explicit instantiation definition shall appear at most once in a
|
| 65 |
+
program,
|
| 66 |
+
- an explicit specialization shall be defined at most once in a program,
|
| 67 |
+
as specified in [[basic.def.odr]], and
|
| 68 |
+
- both an explicit instantiation and a declaration of an explicit
|
| 69 |
+
specialization shall not appear in a program unless the explicit
|
| 70 |
+
specialization is reachable from the explicit instantiation.
|
| 71 |
+
|
| 72 |
+
An implementation is not required to diagnose a violation of this rule
|
| 73 |
+
if neither declaration is reachable from the other.
|
| 74 |
+
|
| 75 |
+
The usual access checking rules do not apply to names in a declaration
|
| 76 |
+
of an explicit instantiation or explicit specialization, with the
|
| 77 |
+
exception of names appearing in a function body, default argument,
|
| 78 |
+
*base-clause*, *member-specification*, *enumerator-list*, or static data
|
| 79 |
+
member or variable template initializer.
|
| 80 |
+
|
| 81 |
+
[*Note 1*: In particular, the template arguments and names used in the
|
| 82 |
+
function declarator (including parameter types, return types and
|
| 83 |
+
exception specifications) can be private types or objects that would
|
| 84 |
+
normally not be accessible. — *end note*]
|
| 85 |
+
|
| 86 |
+
Each class template specialization instantiated from a template has its
|
| 87 |
+
own copy of any static members.
|
| 88 |
+
|
| 89 |
+
[*Example 2*:
|
| 90 |
+
|
| 91 |
+
``` cpp
|
| 92 |
+
template<class T> class X {
|
| 93 |
+
static T s;
|
| 94 |
+
};
|
| 95 |
+
template<class T> T X<T>::s = 0;
|
| 96 |
+
X<int> aa;
|
| 97 |
+
X<char*> bb;
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
`X<int>`
|
| 101 |
+
|
| 102 |
+
has a static member `s` of type `int` and `X<char*>` has a static member
|
| 103 |
+
`s` of type `char*`.
|
| 104 |
+
|
| 105 |
+
— *end example*]
|
| 106 |
+
|
| 107 |
+
If a function declaration acquired its function type through a dependent
|
| 108 |
+
type [[temp.dep.type]] without using the syntactic form of a function
|
| 109 |
+
declarator, the program is ill-formed.
|
| 110 |
+
|
| 111 |
+
[*Example 3*:
|
| 112 |
+
|
| 113 |
+
``` cpp
|
| 114 |
+
template<class T> struct A {
|
| 115 |
+
static T t;
|
| 116 |
+
};
|
| 117 |
+
typedef int function();
|
| 118 |
+
A<function> a; // error: would declare A<function>::t as a static member function
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
— *end example*]
|
| 122 |
+
|