tmp/tmp0iaqemvq/{from.md → to.md}
RENAMED
|
@@ -2,13 +2,13 @@
|
|
| 2 |
|
| 3 |
Template arguments can be deduced in several different contexts, but in
|
| 4 |
each case a type that is specified in terms of template parameters (call
|
| 5 |
it `P`) is compared with an actual type (call it `A`), and an attempt is
|
| 6 |
made to find template argument values (a type for a type parameter, a
|
| 7 |
-
value for a
|
| 8 |
-
that will make `P`, after substitution of the
|
| 9 |
-
the deduced `A`), compatible with `A`.
|
| 10 |
|
| 11 |
In some cases, the deduction is done using a single set of types `P` and
|
| 12 |
`A`, in other cases, there will be a set of corresponding types `P` and
|
| 13 |
`A`. Type deduction is done independently for each `P/A` pair, and the
|
| 14 |
deduced template argument values are then combined. If type deduction
|
|
@@ -18,52 +18,57 @@ pairs yield different deduced values, or if any template argument
|
|
| 18 |
remains neither deduced nor explicitly specified, template argument
|
| 19 |
deduction fails. The type of a type parameter is only deduced from an
|
| 20 |
array bound if it is not otherwise deduced.
|
| 21 |
|
| 22 |
A given type `P` can be composed from a number of other types,
|
| 23 |
-
templates, and
|
| 24 |
|
| 25 |
- A function type includes the types of each of the function parameters,
|
| 26 |
the return type, and its exception specification.
|
| 27 |
- A pointer-to-member type includes the type of the class object pointed
|
| 28 |
to and the type of the member pointed to.
|
| 29 |
- A type that is a specialization of a class template (e.g., `A<int>`)
|
| 30 |
-
includes the types, templates, and
|
| 31 |
-
template argument list of the specialization.
|
| 32 |
- An array type includes the array element type and the value of the
|
| 33 |
array bound.
|
| 34 |
|
| 35 |
-
In most cases, the types, templates, and
|
| 36 |
-
to compose `P` participate in template argument
|
| 37 |
-
may be used to determine the value of a
|
| 38 |
-
argument deduction fails if the value so
|
| 39 |
-
with the values determined elsewhere. In
|
| 40 |
-
value does not participate in type
|
| 41 |
-
values of template arguments that were
|
| 42 |
-
explicitly specified. If a template
|
| 43 |
-
non-deduced contexts and is not explicitly
|
| 44 |
-
deduction fails.
|
| 45 |
|
| 46 |
-
[*Note 1*: Under [[temp.deduct.call]], if `P` contains no
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
The non-deduced contexts are:
|
| 51 |
|
| 52 |
- The *nested-name-specifier* of a type that was specified using a
|
| 53 |
*qualified-id*.
|
|
|
|
|
|
|
| 54 |
- The *expression* of a *decltype-specifier*.
|
| 55 |
-
-
|
|
|
|
| 56 |
subexpression references a template parameter.
|
| 57 |
- A template parameter used in the parameter type of a function
|
| 58 |
parameter that has a default argument that is being used in the call
|
| 59 |
for which argument deduction is being done.
|
| 60 |
- A function parameter for which the associated argument is an overload
|
| 61 |
-
set
|
| 62 |
-
-
|
|
|
|
| 63 |
(resulting in an ambiguous deduction), or
|
| 64 |
-
- no function
|
|
|
|
| 65 |
- the overload set supplied as an argument contains one or more
|
| 66 |
function templates.
|
| 67 |
- A function parameter for which the associated argument is an
|
| 68 |
initializer list [[dcl.init.list]] but the parameter does not have a
|
| 69 |
type for which deduction from an initializer list is specified
|
|
@@ -172,13 +177,15 @@ void t() {
|
|
| 172 |
}
|
| 173 |
```
|
| 174 |
|
| 175 |
— *end example*]
|
| 176 |
|
| 177 |
-
A
|
| 178 |
-
template
|
| 179 |
-
|
|
|
|
|
|
|
| 180 |
|
| 181 |
``` cpp
|
| 182 |
\opt{cv} T
|
| 183 |
T*
|
| 184 |
T&
|
|
@@ -187,47 +194,48 @@ T&&
|
|
| 187 |
\opt{T}(\opt{T}) noexcept(\opt{i})
|
| 188 |
\opt{T} \opt{T}::*
|
| 189 |
\opt{TT}<T>
|
| 190 |
\opt{TT}<i>
|
| 191 |
\opt{TT}<TT>
|
|
|
|
| 192 |
\opt{TT}<>
|
| 193 |
```
|
| 194 |
|
| 195 |
where
|
| 196 |
|
| 197 |
- `\opt{T}` represents a type or parameter-type-list that either
|
| 198 |
satisfies these rules recursively, is a non-deduced context in `P` or
|
| 199 |
`A`, or is the same non-dependent type in `P` and `A`,
|
| 200 |
-
- `\opt{TT}` represents either a class template or a template template
|
| 201 |
-
parameter,
|
| 202 |
- `\opt{i}` represents an expression that either is an `i`, is
|
| 203 |
value-dependent in `P` or `A`, or has the same constant value in `P`
|
| 204 |
-
and `A`,
|
|
|
|
|
|
|
| 205 |
- `noexcept(\opt{i})` represents an exception specification
|
| 206 |
[[except.spec]] in which the (possibly-implicit, see [[dcl.fct]])
|
| 207 |
*noexcept-specifier*’s operand satisfies the rules for an `\opt{i}`
|
| 208 |
above.
|
| 209 |
|
| 210 |
[*Note 2*: If a type matches such a form but contains no `T`s, `i`s, or
|
| 211 |
`TT`s, deduction is not possible. — *end note*]
|
| 212 |
|
| 213 |
-
Similarly, `<
|
| 214 |
-
argument contains
|
| 215 |
-
|
| 216 |
-
|
| 217 |
|
| 218 |
-
If `P` has a form that contains `<T>`
|
| 219 |
-
the respective template argument list of `P` is
|
| 220 |
-
corresponding argument Aᵢ of the corresponding
|
| 221 |
-
`A`. If the template argument list of `P`
|
| 222 |
-
is not the last template argument, the
|
| 223 |
-
a non-deduced context. If `Pᵢ` is a
|
| 224 |
-
`Pᵢ` is compared with each remaining
|
| 225 |
-
list of `A`. Each comparison deduces
|
| 226 |
-
positions in the template parameter
|
| 227 |
-
partial ordering [[temp.deduct.partial]],
|
| 228 |
-
expansion:
|
| 229 |
|
| 230 |
- if `P` does not contain a template argument corresponding to `Aᵢ` then
|
| 231 |
`Aᵢ` is ignored;
|
| 232 |
- otherwise, if `Pᵢ` is not a pack expansion, template argument
|
| 233 |
deduction fails.
|
|
@@ -328,11 +336,11 @@ where type is `X<int>` and `T` is `char[6]`.
|
|
| 328 |
— *end example*]
|
| 329 |
|
| 330 |
Template arguments cannot be deduced from function arguments involving
|
| 331 |
constructs other than the ones specified above.
|
| 332 |
|
| 333 |
-
When the value of the argument corresponding to a
|
| 334 |
parameter `P` that is declared with a dependent type is deduced from an
|
| 335 |
expression, the template parameters in the type of `P` are deduced from
|
| 336 |
the type of the value.
|
| 337 |
|
| 338 |
[*Example 8*:
|
|
@@ -419,12 +427,12 @@ void g() {
|
|
| 419 |
|
| 420 |
— *end note*]
|
| 421 |
|
| 422 |
[*Note 5*:
|
| 423 |
|
| 424 |
-
If, in the declaration of a function template with a
|
| 425 |
-
parameter, the
|
| 426 |
the function parameter list, the expression is a non-deduced context as
|
| 427 |
specified above.
|
| 428 |
|
| 429 |
[*Example 12*:
|
| 430 |
|
|
@@ -465,13 +473,14 @@ int x = deduce<77>(a.xm, 62, b.ym);
|
|
| 465 |
|
| 466 |
— *end note*]
|
| 467 |
|
| 468 |
If `P` has a form that contains `<i>`, and if the type of `i` differs
|
| 469 |
from the type of the corresponding template parameter of the template
|
| 470 |
-
named by the enclosing *simple-template-id*
|
| 471 |
-
|
| 472 |
-
|
|
|
|
| 473 |
|
| 474 |
If `P` has a form that includes `noexcept(i)` and the type of `i` is not
|
| 475 |
`bool`, deduction fails.
|
| 476 |
|
| 477 |
[*Example 13*:
|
|
@@ -531,11 +540,11 @@ void g() {
|
|
| 531 |
}
|
| 532 |
```
|
| 533 |
|
| 534 |
— *end example*]
|
| 535 |
|
| 536 |
-
The *template-argument* corresponding to a template
|
| 537 |
is deduced from the type of the *template-argument* of a class template
|
| 538 |
specialization used in the argument list of a function call.
|
| 539 |
|
| 540 |
[*Example 16*:
|
| 541 |
|
|
|
|
| 2 |
|
| 3 |
Template arguments can be deduced in several different contexts, but in
|
| 4 |
each case a type that is specified in terms of template parameters (call
|
| 5 |
it `P`) is compared with an actual type (call it `A`), and an attempt is
|
| 6 |
made to find template argument values (a type for a type parameter, a
|
| 7 |
+
value for a constant template parameter, or a template for a template
|
| 8 |
+
template parameter) that will make `P`, after substitution of the
|
| 9 |
+
deduced values (call it the deduced `A`), compatible with `A`.
|
| 10 |
|
| 11 |
In some cases, the deduction is done using a single set of types `P` and
|
| 12 |
`A`, in other cases, there will be a set of corresponding types `P` and
|
| 13 |
`A`. Type deduction is done independently for each `P/A` pair, and the
|
| 14 |
deduced template argument values are then combined. If type deduction
|
|
|
|
| 18 |
remains neither deduced nor explicitly specified, template argument
|
| 19 |
deduction fails. The type of a type parameter is only deduced from an
|
| 20 |
array bound if it is not otherwise deduced.
|
| 21 |
|
| 22 |
A given type `P` can be composed from a number of other types,
|
| 23 |
+
templates, and constant template argument values:
|
| 24 |
|
| 25 |
- A function type includes the types of each of the function parameters,
|
| 26 |
the return type, and its exception specification.
|
| 27 |
- A pointer-to-member type includes the type of the class object pointed
|
| 28 |
to and the type of the member pointed to.
|
| 29 |
- A type that is a specialization of a class template (e.g., `A<int>`)
|
| 30 |
+
includes the types, templates, and constant template argument values
|
| 31 |
+
referenced by the template argument list of the specialization.
|
| 32 |
- An array type includes the array element type and the value of the
|
| 33 |
array bound.
|
| 34 |
|
| 35 |
+
In most cases, the types, templates, and constant template argument
|
| 36 |
+
values that are used to compose `P` participate in template argument
|
| 37 |
+
deduction. That is, they may be used to determine the value of a
|
| 38 |
+
template argument, and template argument deduction fails if the value so
|
| 39 |
+
determined is not consistent with the values determined elsewhere. In
|
| 40 |
+
certain contexts, however, the value does not participate in type
|
| 41 |
+
deduction, but instead uses the values of template arguments that were
|
| 42 |
+
either deduced elsewhere or explicitly specified. If a template
|
| 43 |
+
parameter is used only in non-deduced contexts and is not explicitly
|
| 44 |
+
specified, template argument deduction fails.
|
| 45 |
|
| 46 |
+
[*Note 1*: Under [[temp.deduct.call]], if `P` contains no template
|
| 47 |
+
parameters that appear in deduced contexts, no deduction is done, so `P`
|
| 48 |
+
and `A` need not have the same form. — *end note*]
|
| 49 |
|
| 50 |
The non-deduced contexts are:
|
| 51 |
|
| 52 |
- The *nested-name-specifier* of a type that was specified using a
|
| 53 |
*qualified-id*.
|
| 54 |
+
- A *pack-index-specifier* or a *pack-index-expression*.
|
| 55 |
+
- A *type-constraint*.
|
| 56 |
- The *expression* of a *decltype-specifier*.
|
| 57 |
+
- The *constant-expression* of a *splice-specifier*.
|
| 58 |
+
- A constant template argument or an array bound in which a
|
| 59 |
subexpression references a template parameter.
|
| 60 |
- A template parameter used in the parameter type of a function
|
| 61 |
parameter that has a default argument that is being used in the call
|
| 62 |
for which argument deduction is being done.
|
| 63 |
- A function parameter for which the associated argument is an overload
|
| 64 |
+
set such that one or more of the following apply:
|
| 65 |
+
- functions whose associated constraints are satisfied and that do not
|
| 66 |
+
all have the same function type match the function parameter type
|
| 67 |
(resulting in an ambiguous deduction), or
|
| 68 |
+
- no function whose associated constraints are satisfied matches the
|
| 69 |
+
function parameter type, or
|
| 70 |
- the overload set supplied as an argument contains one or more
|
| 71 |
function templates.
|
| 72 |
- A function parameter for which the associated argument is an
|
| 73 |
initializer list [[dcl.init.list]] but the parameter does not have a
|
| 74 |
type for which deduction from an initializer list is specified
|
|
|
|
| 177 |
}
|
| 178 |
```
|
| 179 |
|
| 180 |
— *end example*]
|
| 181 |
|
| 182 |
+
A type template argument `T`, a constant template argument `i`, a
|
| 183 |
+
template template argument `TT` denoting a class template or an alias
|
| 184 |
+
template, or a template template argument `VV` denoting a variable
|
| 185 |
+
template or a concept can be deduced if `P` and `A` have one of the
|
| 186 |
+
following forms:
|
| 187 |
|
| 188 |
``` cpp
|
| 189 |
\opt{cv} T
|
| 190 |
T*
|
| 191 |
T&
|
|
|
|
| 194 |
\opt{T}(\opt{T}) noexcept(\opt{i})
|
| 195 |
\opt{T} \opt{T}::*
|
| 196 |
\opt{TT}<T>
|
| 197 |
\opt{TT}<i>
|
| 198 |
\opt{TT}<TT>
|
| 199 |
+
\opt{TT}<VV>
|
| 200 |
\opt{TT}<>
|
| 201 |
```
|
| 202 |
|
| 203 |
where
|
| 204 |
|
| 205 |
- `\opt{T}` represents a type or parameter-type-list that either
|
| 206 |
satisfies these rules recursively, is a non-deduced context in `P` or
|
| 207 |
`A`, or is the same non-dependent type in `P` and `A`,
|
|
|
|
|
|
|
| 208 |
- `\opt{i}` represents an expression that either is an `i`, is
|
| 209 |
value-dependent in `P` or `A`, or has the same constant value in `P`
|
| 210 |
+
and `A`,
|
| 211 |
+
- `\opt{TT}` represents either a class template or a template template
|
| 212 |
+
parameter, and
|
| 213 |
- `noexcept(\opt{i})` represents an exception specification
|
| 214 |
[[except.spec]] in which the (possibly-implicit, see [[dcl.fct]])
|
| 215 |
*noexcept-specifier*’s operand satisfies the rules for an `\opt{i}`
|
| 216 |
above.
|
| 217 |
|
| 218 |
[*Note 2*: If a type matches such a form but contains no `T`s, `i`s, or
|
| 219 |
`TT`s, deduction is not possible. — *end note*]
|
| 220 |
|
| 221 |
+
Similarly, `<X>` represents template argument lists where at least one
|
| 222 |
+
argument contains an X, where X is one of `T`, `i`, `TT`, or `VV`; and
|
| 223 |
+
`<>` represents template argument lists where no argument contains a
|
| 224 |
+
`T`, an `i`, a `TT`, or a `VV`.
|
| 225 |
|
| 226 |
+
If `P` has a form that contains `<T>`, `<i>`, `<TT>`, or `<VV>`, then
|
| 227 |
+
each argument Pᵢ of the respective template argument list of `P` is
|
| 228 |
+
compared with the corresponding argument Aᵢ of the corresponding
|
| 229 |
+
template argument list of `A`. If the template argument list of `P`
|
| 230 |
+
contains a pack expansion that is not the last template argument, the
|
| 231 |
+
entire template argument list is a non-deduced context. If `Pᵢ` is a
|
| 232 |
+
pack expansion, then the pattern of `Pᵢ` is compared with each remaining
|
| 233 |
+
argument in the template argument list of `A`. Each comparison deduces
|
| 234 |
+
template arguments for subsequent positions in the template parameter
|
| 235 |
+
packs expanded by `Pᵢ`. During partial ordering [[temp.deduct.partial]],
|
| 236 |
+
if `Aᵢ` was originally a pack expansion:
|
| 237 |
|
| 238 |
- if `P` does not contain a template argument corresponding to `Aᵢ` then
|
| 239 |
`Aᵢ` is ignored;
|
| 240 |
- otherwise, if `Pᵢ` is not a pack expansion, template argument
|
| 241 |
deduction fails.
|
|
|
|
| 336 |
— *end example*]
|
| 337 |
|
| 338 |
Template arguments cannot be deduced from function arguments involving
|
| 339 |
constructs other than the ones specified above.
|
| 340 |
|
| 341 |
+
When the value of the argument corresponding to a constant template
|
| 342 |
parameter `P` that is declared with a dependent type is deduced from an
|
| 343 |
expression, the template parameters in the type of `P` are deduced from
|
| 344 |
the type of the value.
|
| 345 |
|
| 346 |
[*Example 8*:
|
|
|
|
| 427 |
|
| 428 |
— *end note*]
|
| 429 |
|
| 430 |
[*Note 5*:
|
| 431 |
|
| 432 |
+
If, in the declaration of a function template with a constant template
|
| 433 |
+
parameter, the constant template parameter is used in a subexpression in
|
| 434 |
the function parameter list, the expression is a non-deduced context as
|
| 435 |
specified above.
|
| 436 |
|
| 437 |
[*Example 12*:
|
| 438 |
|
|
|
|
| 473 |
|
| 474 |
— *end note*]
|
| 475 |
|
| 476 |
If `P` has a form that contains `<i>`, and if the type of `i` differs
|
| 477 |
from the type of the corresponding template parameter of the template
|
| 478 |
+
named by the enclosing *simple-template-id* or
|
| 479 |
+
*splice-specialization-specifier*, deduction fails. If `P` has a form
|
| 480 |
+
that contains `[i]`, and if the type of `i` is not an integral type,
|
| 481 |
+
deduction fails.[^13]
|
| 482 |
|
| 483 |
If `P` has a form that includes `noexcept(i)` and the type of `i` is not
|
| 484 |
`bool`, deduction fails.
|
| 485 |
|
| 486 |
[*Example 13*:
|
|
|
|
| 540 |
}
|
| 541 |
```
|
| 542 |
|
| 543 |
— *end example*]
|
| 544 |
|
| 545 |
+
The *template-argument* corresponding to a template template parameter
|
| 546 |
is deduced from the type of the *template-argument* of a class template
|
| 547 |
specialization used in the argument list of a function call.
|
| 548 |
|
| 549 |
[*Example 16*:
|
| 550 |
|