tmp/tmp23ldhfno/{from.md → to.md}
RENAMED
|
@@ -24,16 +24,16 @@ void h(int* p) {
|
|
| 24 |
```
|
| 25 |
|
| 26 |
— *end example*]
|
| 27 |
|
| 28 |
Such specializations are distinct functions and do not violate the
|
| 29 |
-
one-definition rule
|
| 30 |
|
| 31 |
-
The signature of a function template is defined in
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
[*Note 1*:
|
| 37 |
|
| 38 |
Two distinct function templates may have identical function return types
|
| 39 |
and function parameter lists, even if overload resolution alone cannot
|
|
@@ -71,70 +71,125 @@ template parameters, but it is possible for an expression to reference a
|
|
| 71 |
type parameter. For example, a template type parameter can be used in
|
| 72 |
the `sizeof` operator. — *end note*]
|
| 73 |
|
| 74 |
Two expressions involving template parameters are considered
|
| 75 |
*equivalent* if two function definitions containing the expressions
|
| 76 |
-
would satisfy the one-definition rule
|
| 77 |
-
|
| 78 |
token used to name a template parameter in one expression is replaced by
|
| 79 |
another token that names the same template parameter in the other
|
| 80 |
-
expression.
|
| 81 |
-
are
|
| 82 |
-
|
| 83 |
-
the
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
[*Example 3*:
|
| 87 |
|
| 88 |
``` cpp
|
| 89 |
template <int I, int J> void f(A<I+J>); // #1
|
| 90 |
template <int K, int L> void f(A<K+L>); // same as #1
|
| 91 |
|
| 92 |
template <class T> decltype(g(T())) h();
|
| 93 |
int g(int);
|
| 94 |
-
template <class T> decltype(g(T())) h() // redeclaration of h() uses the earlier lookup
|
| 95 |
-
{ return g(T()); } //
|
| 96 |
int i = h<int>(); // template argument substitution fails; g(int)
|
| 97 |
// was not in scope at the first declaration of h()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
```
|
| 99 |
|
| 100 |
— *end example*]
|
| 101 |
|
| 102 |
-
Two expressions involving template parameters that
|
| 103 |
-
are *functionally equivalent* if, for any given set
|
| 104 |
-
arguments, the evaluation of the expression results in the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
Two function templates are *equivalent* if they are declared in the same
|
| 107 |
-
scope, have the same name, have
|
| 108 |
-
|
| 109 |
-
rules described above to compare
|
| 110 |
-
parameters. Two function templates are
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
the program
|
|
|
|
|
|
|
| 117 |
|
| 118 |
-
[*Note
|
| 119 |
|
| 120 |
This rule guarantees that equivalent declarations will be linked with
|
| 121 |
one another, while not requiring implementations to use heroic efforts
|
| 122 |
to guarantee that functionally equivalent declarations will be treated
|
| 123 |
as distinct. For example, the last two declarations are functionally
|
| 124 |
equivalent and would cause a program to be ill-formed:
|
| 125 |
|
| 126 |
``` cpp
|
| 127 |
-
//
|
| 128 |
template <int I> void f(A<I>, A<I+10>);
|
| 129 |
template <int I> void f(A<I>, A<I+10>);
|
| 130 |
|
| 131 |
-
//
|
| 132 |
template <int I> void f(A<I>, A<I+10>);
|
| 133 |
template <int I> void f(A<I>, A<I+11>);
|
| 134 |
|
| 135 |
-
//
|
| 136 |
template <int I> void f(A<I>, A<I+10>);
|
| 137 |
template <int I> void f(A<I>, A<I+1+2+3+4>);
|
| 138 |
```
|
| 139 |
|
| 140 |
— *end note*]
|
|
|
|
| 24 |
```
|
| 25 |
|
| 26 |
— *end example*]
|
| 27 |
|
| 28 |
Such specializations are distinct functions and do not violate the
|
| 29 |
+
one-definition rule [[basic.def.odr]].
|
| 30 |
|
| 31 |
+
The signature of a function template is defined in [[intro.defs]]. The
|
| 32 |
+
names of the template parameters are significant only for establishing
|
| 33 |
+
the relationship between the template parameters and the rest of the
|
| 34 |
+
signature.
|
| 35 |
|
| 36 |
[*Note 1*:
|
| 37 |
|
| 38 |
Two distinct function templates may have identical function return types
|
| 39 |
and function parameter lists, even if overload resolution alone cannot
|
|
|
|
| 71 |
type parameter. For example, a template type parameter can be used in
|
| 72 |
the `sizeof` operator. — *end note*]
|
| 73 |
|
| 74 |
Two expressions involving template parameters are considered
|
| 75 |
*equivalent* if two function definitions containing the expressions
|
| 76 |
+
would satisfy the one-definition rule [[basic.def.odr]], except that the
|
| 77 |
+
tokens used to name the template parameters may differ as long as a
|
| 78 |
token used to name a template parameter in one expression is replaced by
|
| 79 |
another token that names the same template parameter in the other
|
| 80 |
+
expression. Two unevaluated operands that do not involve template
|
| 81 |
+
parameters are considered equivalent if two function definitions
|
| 82 |
+
containing the expressions would satisfy the one-definition rule, except
|
| 83 |
+
that the tokens used to name types and declarations may differ as long
|
| 84 |
+
as they name the same entities, and the tokens used to form concept-ids
|
| 85 |
+
may differ as long as the two *template-id*s are the same [[temp.type]].
|
| 86 |
+
|
| 87 |
+
[*Note 3*: For instance, `A<42>` and `A<40+2>` name the same
|
| 88 |
+
type. — *end note*]
|
| 89 |
+
|
| 90 |
+
Two *lambda-expression*s are never considered equivalent.
|
| 91 |
+
|
| 92 |
+
[*Note 4*: The intent is to avoid *lambda-expression*s appearing in the
|
| 93 |
+
signature of a function template with external linkage. — *end note*]
|
| 94 |
+
|
| 95 |
+
For determining whether two dependent names [[temp.dep]] are equivalent,
|
| 96 |
+
only the name itself is considered, not the result of name lookup in the
|
| 97 |
+
context of the template. If multiple declarations of the same function
|
| 98 |
+
template differ in the result of this name lookup, the result for the
|
| 99 |
+
first declaration is used.
|
| 100 |
|
| 101 |
[*Example 3*:
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
template <int I, int J> void f(A<I+J>); // #1
|
| 105 |
template <int K, int L> void f(A<K+L>); // same as #1
|
| 106 |
|
| 107 |
template <class T> decltype(g(T())) h();
|
| 108 |
int g(int);
|
| 109 |
+
template <class T> decltype(g(T())) h() // redeclaration of h() uses the earlier lookup…
|
| 110 |
+
{ return g(T()); } // …{} although the lookup here does find g(int)
|
| 111 |
int i = h<int>(); // template argument substitution fails; g(int)
|
| 112 |
// was not in scope at the first declaration of h()
|
| 113 |
+
|
| 114 |
+
// ill-formed, no diagnostic required: the two expressions are functionally equivalent but not equivalent
|
| 115 |
+
template <int N> void foo(const char (*s)[([]{}, N)]);
|
| 116 |
+
template <int N> void foo(const char (*s)[([]{}, N)]);
|
| 117 |
+
|
| 118 |
+
// two different declarations because the non-dependent portions are not considered equivalent
|
| 119 |
+
template <class T> void spam(decltype([]{}) (*s)[sizeof(T)]);
|
| 120 |
+
template <class T> void spam(decltype([]{}) (*s)[sizeof(T)]);
|
| 121 |
```
|
| 122 |
|
| 123 |
— *end example*]
|
| 124 |
|
| 125 |
+
Two potentially-evaluated expressions involving template parameters that
|
| 126 |
+
are not equivalent are *functionally equivalent* if, for any given set
|
| 127 |
+
of template arguments, the evaluation of the expression results in the
|
| 128 |
+
same value. Two unevaluated operands that are not equivalent are
|
| 129 |
+
functionally equivalent if, for any given set of template arguments, the
|
| 130 |
+
expressions perform the same operations in the same order with the same
|
| 131 |
+
entities.
|
| 132 |
+
|
| 133 |
+
[*Note 5*: For instance, one could have redundant
|
| 134 |
+
parentheses. — *end note*]
|
| 135 |
+
|
| 136 |
+
Two *template-head*s are *equivalent* if their
|
| 137 |
+
*template-parameter-list*s have the same length, corresponding
|
| 138 |
+
*template-parameter*s are equivalent and are both declared with
|
| 139 |
+
*type-constraint*s that are equivalent if either *template-parameter* is
|
| 140 |
+
declared with a *type-constraint*, and if either *template-head* has a
|
| 141 |
+
*requires-clause*, they both have *requires-clause*s and the
|
| 142 |
+
corresponding *constraint-expression*s are equivalent. Two
|
| 143 |
+
*template-parameter*s are *equivalent* under the following conditions:
|
| 144 |
+
|
| 145 |
+
- they declare template parameters of the same kind,
|
| 146 |
+
- if either declares a template parameter pack, they both do,
|
| 147 |
+
- if they declare non-type template parameters, they have equivalent
|
| 148 |
+
types ignoring the use of *type-constraint*s for placeholder types,
|
| 149 |
+
and
|
| 150 |
+
- if they declare template template parameters, their template
|
| 151 |
+
parameters are equivalent.
|
| 152 |
+
|
| 153 |
+
When determining whether types or *type-constraint*s are equivalent, the
|
| 154 |
+
rules above are used to compare expressions involving template
|
| 155 |
+
parameters. Two *template-head*s are *functionally equivalent* if they
|
| 156 |
+
accept and are satisfied by [[temp.constr.constr]] the same set of
|
| 157 |
+
template argument lists.
|
| 158 |
|
| 159 |
Two function templates are *equivalent* if they are declared in the same
|
| 160 |
+
scope, have the same name, have equivalent *template-head*s, and have
|
| 161 |
+
return types, parameter lists, and trailing *requires-clause*s (if any)
|
| 162 |
+
that are equivalent using the rules described above to compare
|
| 163 |
+
expressions involving template parameters. Two function templates are
|
| 164 |
+
*functionally equivalent* if they are declared in the same scope, have
|
| 165 |
+
the same name, accept and are satisfied by the same set of template
|
| 166 |
+
argument lists, and have return types and parameter lists that are
|
| 167 |
+
functionally equivalent using the rules described above to compare
|
| 168 |
+
expressions involving template parameters. If the validity or meaning of
|
| 169 |
+
the program depends on whether two constructs are equivalent, and they
|
| 170 |
+
are functionally equivalent but not equivalent, the program is
|
| 171 |
+
ill-formed, no diagnostic required.
|
| 172 |
|
| 173 |
+
[*Note 6*:
|
| 174 |
|
| 175 |
This rule guarantees that equivalent declarations will be linked with
|
| 176 |
one another, while not requiring implementations to use heroic efforts
|
| 177 |
to guarantee that functionally equivalent declarations will be treated
|
| 178 |
as distinct. For example, the last two declarations are functionally
|
| 179 |
equivalent and would cause a program to be ill-formed:
|
| 180 |
|
| 181 |
``` cpp
|
| 182 |
+
// guaranteed to be the same
|
| 183 |
template <int I> void f(A<I>, A<I+10>);
|
| 184 |
template <int I> void f(A<I>, A<I+10>);
|
| 185 |
|
| 186 |
+
// guaranteed to be different
|
| 187 |
template <int I> void f(A<I>, A<I+10>);
|
| 188 |
template <int I> void f(A<I>, A<I+11>);
|
| 189 |
|
| 190 |
+
// ill-formed, no diagnostic required
|
| 191 |
template <int I> void f(A<I>, A<I+10>);
|
| 192 |
template <int I> void f(A<I>, A<I+1+2+3+4>);
|
| 193 |
```
|
| 194 |
|
| 195 |
— *end note*]
|