tmp/tmpks3s1d9w/{from.md → to.md}
RENAMED
|
@@ -10,15 +10,17 @@ template<class T1, int I> void sort<T1, I>(T1 data[I]); // error
|
|
| 10 |
```
|
| 11 |
|
| 12 |
However, this syntax is allowed in class template partial
|
| 13 |
specializations ([[temp.class.spec]]).
|
| 14 |
|
| 15 |
-
For purposes of name lookup and instantiation, default arguments
|
| 16 |
-
function templates and default arguments
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
|
| 21 |
Because an *alias-declaration* cannot declare a *template-id*, it is not
|
| 22 |
possible to partially or explicitly specialize an alias template.
|
| 23 |
|
| 24 |
### Class templates <a id="temp.class">[[temp.class]]</a>
|
|
@@ -122,12 +124,12 @@ v1[3] = 7; // Array<int>::operator[]()
|
|
| 122 |
v2[3] = dcomplex(7,8); // Array<dcomplex>::operator[]()
|
| 123 |
```
|
| 124 |
|
| 125 |
#### Member classes of class templates <a id="temp.mem.class">[[temp.mem.class]]</a>
|
| 126 |
|
| 127 |
-
A
|
| 128 |
-
template definition in which it is declared. The
|
| 129 |
defined before its first use that requires an instantiation (
|
| 130 |
[[temp.inst]]). For example,
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
template<class T> struct A {
|
|
@@ -138,18 +140,27 @@ template<class T> class A<T>::B { };
|
|
| 138 |
A<int>::B b2; // OK: requires A::B to be defined
|
| 139 |
```
|
| 140 |
|
| 141 |
#### Static data members of class templates <a id="temp.static">[[temp.static]]</a>
|
| 142 |
|
| 143 |
-
A definition for a static data member
|
| 144 |
-
scope enclosing the definition of the static
|
|
|
|
| 145 |
|
| 146 |
``` cpp
|
| 147 |
template<class T> class X {
|
| 148 |
static T s;
|
| 149 |
};
|
| 150 |
template<class T> T X<T>::s = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
```
|
| 152 |
|
| 153 |
An explicit specialization of a static data member declared as an array
|
| 154 |
of unknown bound can have a different bound from its definition, if any.
|
| 155 |
|
|
@@ -193,27 +204,27 @@ template<class T> struct string {
|
|
| 193 |
|
| 194 |
template<class T> template<class T2> int string<T>::compare(const T2& s) {
|
| 195 |
}
|
| 196 |
```
|
| 197 |
|
| 198 |
-
A local class shall not have member templates.
|
| 199 |
-
(Clause [[class.access]]) apply to member template
|
| 200 |
-
shall not be a member template. A
|
| 201 |
-
with a given name and type and a member
|
| 202 |
-
name, which could be used to generate a
|
| 203 |
-
can both be declared in a class. When
|
| 204 |
-
type refers to the non-template
|
| 205 |
-
argument list is supplied.
|
| 206 |
|
| 207 |
``` cpp
|
| 208 |
template <class T> struct A {
|
| 209 |
void f(int);
|
| 210 |
template <class T2> void f(T2);
|
| 211 |
};
|
| 212 |
|
| 213 |
-
template <> void A<int>::f(int) { } // non-template member
|
| 214 |
-
template <> template <> void A<int>::f<>(int) { } // template
|
| 215 |
|
| 216 |
int main() {
|
| 217 |
A<char> ac;
|
| 218 |
ac.f(1); // non-template
|
| 219 |
ac.f('c'); // template
|
|
@@ -330,12 +341,13 @@ the following contexts:
|
|
| 330 |
*type-parameter* without the ellipsis.
|
| 331 |
- In an *initializer-list* ([[dcl.init]]); the pattern is an
|
| 332 |
*initializer-clause*.
|
| 333 |
- In a *base-specifier-list* (Clause [[class.derived]]); the pattern is
|
| 334 |
a *base-specifier*.
|
| 335 |
-
- In a *mem-initializer-list* ([[class.base.init]])
|
| 336 |
-
*mem-initializer*
|
|
|
|
| 337 |
- In a *template-argument-list* ([[temp.arg]]); the pattern is a
|
| 338 |
*template-argument*.
|
| 339 |
- In a *dynamic-exception-specification* ([[except.spec]]); the pattern
|
| 340 |
is a *type-id*.
|
| 341 |
- In an *attribute-list* ([[dcl.attr.grammar]]); the pattern is an
|
|
@@ -345,10 +357,15 @@ the following contexts:
|
|
| 345 |
- In a *capture-list* ([[expr.prim.lambda]]); the pattern is a
|
| 346 |
*capture*.
|
| 347 |
- In a `sizeof...` expression ([[expr.sizeof]]); the pattern is an
|
| 348 |
*identifier*.
|
| 349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
``` cpp
|
| 351 |
template<class ... Types> void f(Types ... rest);
|
| 352 |
template<class ... Types> void g(Types ... rest) {
|
| 353 |
f(&rest ...); // ``&rest ...'' is a pack expansion; ``&rest'' is its pattern
|
| 354 |
}
|
|
@@ -392,18 +409,28 @@ template<class ... Args>
|
|
| 392 |
The instantiation of a pack expansion that is not a `sizeof...`
|
| 393 |
expression produces a list
|
| 394 |
$\mathtt{E}_1, \mathtt{E}_2, ..., \mathtt{E}_N$, where N is the number
|
| 395 |
of elements in the pack expansion parameters. Each Eᵢ is generated by
|
| 396 |
instantiating the pattern and replacing each pack expansion parameter
|
| 397 |
-
with its ith element.
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
the
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
|
| 406 |
``` cpp
|
| 407 |
template<class... T> struct X : T... { };
|
| 408 |
template<class... T> void f(T... values) {
|
| 409 |
X<T...> x(values...);
|
|
@@ -419,25 +446,25 @@ parameter pack it expands.
|
|
| 419 |
|
| 420 |
### Friends <a id="temp.friend">[[temp.friend]]</a>
|
| 421 |
|
| 422 |
A friend of a class or class template can be a function template or
|
| 423 |
class template, a specialization of a function template or class
|
| 424 |
-
template, or
|
| 425 |
-
|
| 426 |
|
| 427 |
- if the name of the friend is a qualified or unqualified *template-id*,
|
| 428 |
the friend declaration refers to a specialization of a function
|
| 429 |
-
template, otherwise
|
| 430 |
- if the name of the friend is a *qualified-id* and a matching
|
| 431 |
non-template function is found in the specified class or namespace,
|
| 432 |
the friend declaration refers to that function, otherwise,
|
| 433 |
- if the name of the friend is a *qualified-id* and a matching function
|
| 434 |
template is found in the specified class or namespace, the friend
|
| 435 |
declaration refers to the deduced specialization of that function
|
| 436 |
template ([[temp.deduct.decl]]), otherwise,
|
| 437 |
-
- the name shall be an *unqualified-id* that declares (or redeclares)
|
| 438 |
-
|
| 439 |
|
| 440 |
``` cpp
|
| 441 |
template<class T> class task;
|
| 442 |
template<class T> task<T>* preempt(task<T>*);
|
| 443 |
|
|
@@ -455,11 +482,11 @@ template<class T> class task {
|
|
| 455 |
Here, each specialization of the `task` class template has the function
|
| 456 |
`next_time` as a friend; because `process` does not have explicit
|
| 457 |
*template-argument*s, each specialization of the `task` class template
|
| 458 |
has an appropriately typed function `process` as a friend, and this
|
| 459 |
friend is not a function template specialization; because the friend
|
| 460 |
-
`preempt` has an explicit *template-argument* `
|
| 461 |
of the `task` class template has the appropriate specialization of the
|
| 462 |
function template `preempt` as a friend; and each specialization of the
|
| 463 |
`task` class template has all specializations of the function template
|
| 464 |
`func` as friends. Similarly, each specialization of the `task` class
|
| 465 |
template has the class template specialization `task<int>` as a friend,
|
|
@@ -494,14 +521,14 @@ class X {
|
|
| 494 |
template<class T> struct A { X::Y ab; }; // OK
|
| 495 |
template<class T> struct A<T*> { X::Y ab; }; // OK
|
| 496 |
```
|
| 497 |
|
| 498 |
When a function is defined in a friend function declaration in a class
|
| 499 |
-
template, the function is instantiated when the function is odr-used
|
| 500 |
-
The same restrictions on multiple declarations and
|
| 501 |
-
apply to non-template function declarations and
|
| 502 |
-
to these implicit definitions.
|
| 503 |
|
| 504 |
A member of a class template may be declared to be a friend of a
|
| 505 |
non-template class. In this case, the corresponding member of every
|
| 506 |
specialization of the class template is a friend of the class granting
|
| 507 |
friendship. For explicit specializations the corresponding member is the
|
|
@@ -669,10 +696,12 @@ following restrictions apply:
|
|
| 669 |
int array[5];
|
| 670 |
template< int X > class A<X,&array> { }; // error
|
| 671 |
```
|
| 672 |
- The argument list of the specialization shall not be identical to the
|
| 673 |
implicit argument list of the primary template.
|
|
|
|
|
|
|
| 674 |
- The template parameter list of a specialization shall not contain
|
| 675 |
default template argument values.[^4]
|
| 676 |
- An argument shall not contain an unexpanded parameter pack. If an
|
| 677 |
argument is a pack expansion ([[temp.variadic]]), it shall be the
|
| 678 |
last argument in the template argument list.
|
|
@@ -837,12 +866,12 @@ family of sort functions might be declared like this:
|
|
| 837 |
template<class T> class Array { };
|
| 838 |
template<class T> void sort(Array<T>&);
|
| 839 |
```
|
| 840 |
|
| 841 |
A function template can be overloaded with other function templates and
|
| 842 |
-
with
|
| 843 |
-
to a function template (i.e., it is never considered to be a
|
| 844 |
specialization), even if it has the same name and type as a potentially
|
| 845 |
generated function template specialization.[^5]
|
| 846 |
|
| 847 |
#### Function template overloading <a id="temp.over.link">[[temp.over.link]]</a>
|
| 848 |
|
|
@@ -907,15 +936,26 @@ Two expressions involving template parameters are considered
|
|
| 907 |
*equivalent* if two function definitions containing the expressions
|
| 908 |
would satisfy the one definition rule ([[basic.def.odr]]), except that
|
| 909 |
the tokens used to name the template parameters may differ as long as a
|
| 910 |
token used to name a template parameter in one expression is replaced by
|
| 911 |
another token that names the same template parameter in the other
|
| 912 |
-
expression.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 913 |
|
| 914 |
``` cpp
|
| 915 |
template <int I, int J> void f(A<I+J>); // #1
|
| 916 |
template <int K, int L> void f(A<K+L>); // same as #1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 917 |
```
|
| 918 |
|
| 919 |
Two expressions involving template parameters that are not equivalent
|
| 920 |
are *functionally equivalent* if, for any given set of template
|
| 921 |
arguments, the evaluation of the expression results in the same value.
|
|
@@ -982,18 +1022,19 @@ specialized template is the one chosen by the partial ordering process.
|
|
| 982 |
To produce the transformed template, for each type, non-type, or
|
| 983 |
template template parameter (including template parameter packs (
|
| 984 |
[[temp.variadic]]) thereof) synthesize a unique type, value, or class
|
| 985 |
template respectively and substitute it for each occurrence of that
|
| 986 |
parameter in the function type of the template. If only one of the
|
| 987 |
-
function templates is a non-static member
|
| 988 |
-
considered to have a new first parameter inserted
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
|
|
|
| 995 |
|
| 996 |
``` cpp
|
| 997 |
struct A { };
|
| 998 |
template<class T> struct B {
|
| 999 |
template<class R> int operator*(R&); // #1
|
|
|
|
| 10 |
```
|
| 11 |
|
| 12 |
However, this syntax is allowed in class template partial
|
| 13 |
specializations ([[temp.class.spec]]).
|
| 14 |
|
| 15 |
+
For purposes of name lookup and instantiation, default arguments and
|
| 16 |
+
*exception-specification*s of function templates and default arguments
|
| 17 |
+
and *exception-specification*s of member functions of class templates
|
| 18 |
+
are considered definitions; each default argument or
|
| 19 |
+
*exception-specification* is a separate definition which is unrelated to
|
| 20 |
+
the function template definition or to any other default arguments or
|
| 21 |
+
*exception-specification*s.
|
| 22 |
|
| 23 |
Because an *alias-declaration* cannot declare a *template-id*, it is not
|
| 24 |
possible to partially or explicitly specialize an alias template.
|
| 25 |
|
| 26 |
### Class templates <a id="temp.class">[[temp.class]]</a>
|
|
|
|
| 124 |
v2[3] = dcomplex(7,8); // Array<dcomplex>::operator[]()
|
| 125 |
```
|
| 126 |
|
| 127 |
#### Member classes of class templates <a id="temp.mem.class">[[temp.mem.class]]</a>
|
| 128 |
|
| 129 |
+
A member class of a class template may be defined outside the class
|
| 130 |
+
template definition in which it is declared. The member class must be
|
| 131 |
defined before its first use that requires an instantiation (
|
| 132 |
[[temp.inst]]). For example,
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
template<class T> struct A {
|
|
|
|
| 140 |
A<int>::B b2; // OK: requires A::B to be defined
|
| 141 |
```
|
| 142 |
|
| 143 |
#### Static data members of class templates <a id="temp.static">[[temp.static]]</a>
|
| 144 |
|
| 145 |
+
A definition for a static data member or static data member template may
|
| 146 |
+
be provided in a namespace scope enclosing the definition of the static
|
| 147 |
+
member’s class template.
|
| 148 |
|
| 149 |
``` cpp
|
| 150 |
template<class T> class X {
|
| 151 |
static T s;
|
| 152 |
};
|
| 153 |
template<class T> T X<T>::s = 0;
|
| 154 |
+
|
| 155 |
+
struct limits {
|
| 156 |
+
template<class T>
|
| 157 |
+
static const T min; // declaration
|
| 158 |
+
};
|
| 159 |
+
|
| 160 |
+
template<class T>
|
| 161 |
+
const T limits::min = { }; // definition
|
| 162 |
```
|
| 163 |
|
| 164 |
An explicit specialization of a static data member declared as an array
|
| 165 |
of unknown bound can have a different bound from its definition, if any.
|
| 166 |
|
|
|
|
| 204 |
|
| 205 |
template<class T> template<class T2> int string<T>::compare(const T2& s) {
|
| 206 |
}
|
| 207 |
```
|
| 208 |
|
| 209 |
+
A local class of non-closure type shall not have member templates.
|
| 210 |
+
Access control rules (Clause [[class.access]]) apply to member template
|
| 211 |
+
names. A destructor shall not be a member template. A non-template
|
| 212 |
+
member function ([[dcl.fct]]) with a given name and type and a member
|
| 213 |
+
function template of the same name, which could be used to generate a
|
| 214 |
+
specialization of the same type, can both be declared in a class. When
|
| 215 |
+
both exist, a use of that name and type refers to the non-template
|
| 216 |
+
member unless an explicit template argument list is supplied.
|
| 217 |
|
| 218 |
``` cpp
|
| 219 |
template <class T> struct A {
|
| 220 |
void f(int);
|
| 221 |
template <class T2> void f(T2);
|
| 222 |
};
|
| 223 |
|
| 224 |
+
template <> void A<int>::f(int) { } // non-template member function
|
| 225 |
+
template <> template <> void A<int>::f<>(int) { } // member function template specialization
|
| 226 |
|
| 227 |
int main() {
|
| 228 |
A<char> ac;
|
| 229 |
ac.f(1); // non-template
|
| 230 |
ac.f('c'); // template
|
|
|
|
| 341 |
*type-parameter* without the ellipsis.
|
| 342 |
- In an *initializer-list* ([[dcl.init]]); the pattern is an
|
| 343 |
*initializer-clause*.
|
| 344 |
- In a *base-specifier-list* (Clause [[class.derived]]); the pattern is
|
| 345 |
a *base-specifier*.
|
| 346 |
+
- In a *mem-initializer-list* ([[class.base.init]]) for a
|
| 347 |
+
*mem-initializer* whose *mem-initializer-id* denotes a base class; the
|
| 348 |
+
pattern is the *mem-initializer*.
|
| 349 |
- In a *template-argument-list* ([[temp.arg]]); the pattern is a
|
| 350 |
*template-argument*.
|
| 351 |
- In a *dynamic-exception-specification* ([[except.spec]]); the pattern
|
| 352 |
is a *type-id*.
|
| 353 |
- In an *attribute-list* ([[dcl.attr.grammar]]); the pattern is an
|
|
|
|
| 357 |
- In a *capture-list* ([[expr.prim.lambda]]); the pattern is a
|
| 358 |
*capture*.
|
| 359 |
- In a `sizeof...` expression ([[expr.sizeof]]); the pattern is an
|
| 360 |
*identifier*.
|
| 361 |
|
| 362 |
+
For the purpose of determining whether a parameter pack satisfies a rule
|
| 363 |
+
regarding entities other than parameter packs, the parameter pack is
|
| 364 |
+
considered to be the entity that would result from an instantiation of
|
| 365 |
+
the pattern in which it appears.
|
| 366 |
+
|
| 367 |
``` cpp
|
| 368 |
template<class ... Types> void f(Types ... rest);
|
| 369 |
template<class ... Types> void g(Types ... rest) {
|
| 370 |
f(&rest ...); // ``&rest ...'' is a pack expansion; ``&rest'' is its pattern
|
| 371 |
}
|
|
|
|
| 409 |
The instantiation of a pack expansion that is not a `sizeof...`
|
| 410 |
expression produces a list
|
| 411 |
$\mathtt{E}_1, \mathtt{E}_2, ..., \mathtt{E}_N$, where N is the number
|
| 412 |
of elements in the pack expansion parameters. Each Eᵢ is generated by
|
| 413 |
instantiating the pattern and replacing each pack expansion parameter
|
| 414 |
+
with its ith element. Such an element, in the context of the
|
| 415 |
+
instantiation, is interpreted as follows:
|
| 416 |
+
|
| 417 |
+
- if the pack is a template parameter pack, the element is a template
|
| 418 |
+
parameter ([[temp.param]]) of the corresponding kind (type or
|
| 419 |
+
non-type) designating the type or value from the template argument;
|
| 420 |
+
otherwise,
|
| 421 |
+
- if the pack is a function parameter pack, the element is an
|
| 422 |
+
*id-expression* designating the function parameter that resulted from
|
| 423 |
+
the instantiation of the pattern where the pack is declared.
|
| 424 |
+
|
| 425 |
+
All of the Eᵢ become elements in the enclosing list. The variety of list
|
| 426 |
+
varies with the context: *expression-list*, *base-specifier-list*,
|
| 427 |
+
*template-argument-list*, etc. When N is zero, the instantiation of the
|
| 428 |
+
expansion produces an empty list. Such an instantiation does not alter
|
| 429 |
+
the syntactic interpretation of the enclosing construct, even in cases
|
| 430 |
+
where omitting the list entirely would otherwise be ill-formed or would
|
| 431 |
+
result in an ambiguity in the grammar.
|
| 432 |
|
| 433 |
``` cpp
|
| 434 |
template<class... T> struct X : T... { };
|
| 435 |
template<class... T> void f(T... values) {
|
| 436 |
X<T...> x(values...);
|
|
|
|
| 446 |
|
| 447 |
### Friends <a id="temp.friend">[[temp.friend]]</a>
|
| 448 |
|
| 449 |
A friend of a class or class template can be a function template or
|
| 450 |
class template, a specialization of a function template or class
|
| 451 |
+
template, or a non-template function or class. For a friend function
|
| 452 |
+
declaration that is not a template declaration:
|
| 453 |
|
| 454 |
- if the name of the friend is a qualified or unqualified *template-id*,
|
| 455 |
the friend declaration refers to a specialization of a function
|
| 456 |
+
template, otherwise,
|
| 457 |
- if the name of the friend is a *qualified-id* and a matching
|
| 458 |
non-template function is found in the specified class or namespace,
|
| 459 |
the friend declaration refers to that function, otherwise,
|
| 460 |
- if the name of the friend is a *qualified-id* and a matching function
|
| 461 |
template is found in the specified class or namespace, the friend
|
| 462 |
declaration refers to the deduced specialization of that function
|
| 463 |
template ([[temp.deduct.decl]]), otherwise,
|
| 464 |
+
- the name shall be an *unqualified-id* that declares (or redeclares) a
|
| 465 |
+
non-template function.
|
| 466 |
|
| 467 |
``` cpp
|
| 468 |
template<class T> class task;
|
| 469 |
template<class T> task<T>* preempt(task<T>*);
|
| 470 |
|
|
|
|
| 482 |
Here, each specialization of the `task` class template has the function
|
| 483 |
`next_time` as a friend; because `process` does not have explicit
|
| 484 |
*template-argument*s, each specialization of the `task` class template
|
| 485 |
has an appropriately typed function `process` as a friend, and this
|
| 486 |
friend is not a function template specialization; because the friend
|
| 487 |
+
`preempt` has an explicit *template-argument* `T`, each specialization
|
| 488 |
of the `task` class template has the appropriate specialization of the
|
| 489 |
function template `preempt` as a friend; and each specialization of the
|
| 490 |
`task` class template has all specializations of the function template
|
| 491 |
`func` as friends. Similarly, each specialization of the `task` class
|
| 492 |
template has the class template specialization `task<int>` as a friend,
|
|
|
|
| 521 |
template<class T> struct A { X::Y ab; }; // OK
|
| 522 |
template<class T> struct A<T*> { X::Y ab; }; // OK
|
| 523 |
```
|
| 524 |
|
| 525 |
When a function is defined in a friend function declaration in a class
|
| 526 |
+
template, the function is instantiated when the function is odr-used (
|
| 527 |
+
[[basic.def.odr]]). The same restrictions on multiple declarations and
|
| 528 |
+
definitions that apply to non-template function declarations and
|
| 529 |
+
definitions also apply to these implicit definitions.
|
| 530 |
|
| 531 |
A member of a class template may be declared to be a friend of a
|
| 532 |
non-template class. In this case, the corresponding member of every
|
| 533 |
specialization of the class template is a friend of the class granting
|
| 534 |
friendship. For explicit specializations the corresponding member is the
|
|
|
|
| 696 |
int array[5];
|
| 697 |
template< int X > class A<X,&array> { }; // error
|
| 698 |
```
|
| 699 |
- The argument list of the specialization shall not be identical to the
|
| 700 |
implicit argument list of the primary template.
|
| 701 |
+
- The specialization shall be more specialized than the primary
|
| 702 |
+
template ([[temp.class.order]]).
|
| 703 |
- The template parameter list of a specialization shall not contain
|
| 704 |
default template argument values.[^4]
|
| 705 |
- An argument shall not contain an unexpanded parameter pack. If an
|
| 706 |
argument is a pack expansion ([[temp.variadic]]), it shall be the
|
| 707 |
last argument in the template argument list.
|
|
|
|
| 866 |
template<class T> class Array { };
|
| 867 |
template<class T> void sort(Array<T>&);
|
| 868 |
```
|
| 869 |
|
| 870 |
A function template can be overloaded with other function templates and
|
| 871 |
+
with non-template functions ([[dcl.fct]]). A non-template function is
|
| 872 |
+
not related to a function template (i.e., it is never considered to be a
|
| 873 |
specialization), even if it has the same name and type as a potentially
|
| 874 |
generated function template specialization.[^5]
|
| 875 |
|
| 876 |
#### Function template overloading <a id="temp.over.link">[[temp.over.link]]</a>
|
| 877 |
|
|
|
|
| 936 |
*equivalent* if two function definitions containing the expressions
|
| 937 |
would satisfy the one definition rule ([[basic.def.odr]]), except that
|
| 938 |
the tokens used to name the template parameters may differ as long as a
|
| 939 |
token used to name a template parameter in one expression is replaced by
|
| 940 |
another token that names the same template parameter in the other
|
| 941 |
+
expression. For determining whether two dependent names ([[temp.dep]])
|
| 942 |
+
are equivalent, only the name itself is considered, not the result of
|
| 943 |
+
name lookup in the context of the template. If multiple declarations of
|
| 944 |
+
the same function template differ in the result of this name lookup, the
|
| 945 |
+
result for the first declaration is used.
|
| 946 |
|
| 947 |
``` cpp
|
| 948 |
template <int I, int J> void f(A<I+J>); // #1
|
| 949 |
template <int K, int L> void f(A<K+L>); // same as #1
|
| 950 |
+
|
| 951 |
+
template <class T> decltype(g(T())) h();
|
| 952 |
+
int g(int);
|
| 953 |
+
template <class T> decltype(g(T())) h() // redeclaration of h() uses the earlier lookup
|
| 954 |
+
{ return g(T()); } // ...although the lookup here does find g(int)
|
| 955 |
+
int i = h<int>(); // template argument substitution fails; g(int)
|
| 956 |
+
// was not in scope at the first declaration of h()
|
| 957 |
```
|
| 958 |
|
| 959 |
Two expressions involving template parameters that are not equivalent
|
| 960 |
are *functionally equivalent* if, for any given set of template
|
| 961 |
arguments, the evaluation of the expression results in the same value.
|
|
|
|
| 1022 |
To produce the transformed template, for each type, non-type, or
|
| 1023 |
template template parameter (including template parameter packs (
|
| 1024 |
[[temp.variadic]]) thereof) synthesize a unique type, value, or class
|
| 1025 |
template respectively and substitute it for each occurrence of that
|
| 1026 |
parameter in the function type of the template. If only one of the
|
| 1027 |
+
function templates is a non-static member of some class `A`, that
|
| 1028 |
+
function template is considered to have a new first parameter inserted
|
| 1029 |
+
in its function parameter list. Given cv as the cv-qualifiers of the
|
| 1030 |
+
function template (if any), the new parameter is of type “rvalue
|
| 1031 |
+
reference to cv `A`” if the optional *ref-qualifier* of the function
|
| 1032 |
+
template is `&&`, or of type “lvalue reference to cv `A`” otherwise.
|
| 1033 |
+
This allows a non-static member to be ordered with respect to a
|
| 1034 |
+
nonmember function and for the results to be equivalent to the ordering
|
| 1035 |
+
of two equivalent nonmembers.
|
| 1036 |
|
| 1037 |
``` cpp
|
| 1038 |
struct A { };
|
| 1039 |
template<class T> struct B {
|
| 1040 |
template<class R> int operator*(R&); // #1
|