tmp/tmph2tc49ux/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### Decltype specifiers <a id="dcl.type.decltype">[[dcl.type.decltype]]</a>
|
| 2 |
+
|
| 3 |
+
``` bnf
|
| 4 |
+
decltype-specifier:
|
| 5 |
+
decltype '(' expression ')'
|
| 6 |
+
```
|
| 7 |
+
|
| 8 |
+
For an expression E, the type denoted by `decltype(E)` is defined as
|
| 9 |
+
follows:
|
| 10 |
+
|
| 11 |
+
- if E is an unparenthesized *id-expression* naming a structured binding
|
| 12 |
+
[[dcl.struct.bind]], `decltype(E)` is the referenced type as given in
|
| 13 |
+
the specification of the structured binding declaration;
|
| 14 |
+
- otherwise, if E is an unparenthesized *id-expression* naming a
|
| 15 |
+
non-type *template-parameter* [[temp.param]], `decltype(E)` is the
|
| 16 |
+
type of the *template-parameter* after performing any necessary type
|
| 17 |
+
deduction ([[dcl.spec.auto]], [[dcl.type.class.deduct]]);
|
| 18 |
+
- otherwise, if E is an unparenthesized *id-expression* or an
|
| 19 |
+
unparenthesized class member access [[expr.ref]], `decltype(E)` is the
|
| 20 |
+
type of the entity named by E. If there is no such entity, or if E
|
| 21 |
+
names a set of overloaded functions, the program is ill-formed;
|
| 22 |
+
- otherwise, if E is an xvalue, `decltype(E)` is `T&&`, where `T` is the
|
| 23 |
+
type of E;
|
| 24 |
+
- otherwise, if E is an lvalue, `decltype(E)` is `T&`, where `T` is the
|
| 25 |
+
type of E;
|
| 26 |
+
- otherwise, `decltype(E)` is the type of E.
|
| 27 |
+
|
| 28 |
+
The operand of the `decltype` specifier is an unevaluated operand
|
| 29 |
+
[[expr.prop]].
|
| 30 |
+
|
| 31 |
+
[*Example 1*:
|
| 32 |
+
|
| 33 |
+
``` cpp
|
| 34 |
+
const int&& foo();
|
| 35 |
+
int i;
|
| 36 |
+
struct A { double x; };
|
| 37 |
+
const A* a = new A();
|
| 38 |
+
decltype(foo()) x1 = 17; // type is const int&&
|
| 39 |
+
decltype(i) x2; // type is int
|
| 40 |
+
decltype(a->x) x3; // type is double
|
| 41 |
+
decltype((a->x)) x4 = x3; // type is const double&
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
— *end example*]
|
| 45 |
+
|
| 46 |
+
[*Note 1*: The rules for determining types involving `decltype(auto)`
|
| 47 |
+
are specified in [[dcl.spec.auto]]. — *end note*]
|
| 48 |
+
|
| 49 |
+
If the operand of a *decltype-specifier* is a prvalue and is not a
|
| 50 |
+
(possibly parenthesized) immediate invocation [[expr.const]], the
|
| 51 |
+
temporary materialization conversion is not applied [[conv.rval]] and no
|
| 52 |
+
result object is provided for the prvalue. The type of the prvalue may
|
| 53 |
+
be incomplete or an abstract class type.
|
| 54 |
+
|
| 55 |
+
[*Note 2*: As a result, storage is not allocated for the prvalue and it
|
| 56 |
+
is not destroyed. Thus, a class type is not instantiated as a result of
|
| 57 |
+
being the type of a function call in this context. In this context, the
|
| 58 |
+
common purpose of writing the expression is merely to refer to its type.
|
| 59 |
+
In that sense, a *decltype-specifier* is analogous to a use of a
|
| 60 |
+
*typedef-name*, so the usual reasons for requiring a complete type do
|
| 61 |
+
not apply. In particular, it is not necessary to allocate storage for a
|
| 62 |
+
temporary object or to enforce the semantic constraints associated with
|
| 63 |
+
invoking the type’s destructor. — *end note*]
|
| 64 |
+
|
| 65 |
+
[*Note 3*: Unlike the preceding rule, parentheses have no special
|
| 66 |
+
meaning in this context. — *end note*]
|
| 67 |
+
|
| 68 |
+
[*Example 2*:
|
| 69 |
+
|
| 70 |
+
``` cpp
|
| 71 |
+
template<class T> struct A { ~A() = delete; };
|
| 72 |
+
template<class T> auto h()
|
| 73 |
+
-> A<T>;
|
| 74 |
+
template<class T> auto i(T) // identity
|
| 75 |
+
-> T;
|
| 76 |
+
template<class T> auto f(T) // #1
|
| 77 |
+
-> decltype(i(h<T>())); // forces completion of A<T> and implicitly uses A<T>::~A()
|
| 78 |
+
// for the temporary introduced by the use of h().
|
| 79 |
+
// (A temporary is not introduced as a result of the use of i().)
|
| 80 |
+
template<class T> auto f(T) // #2
|
| 81 |
+
-> void;
|
| 82 |
+
auto g() -> void {
|
| 83 |
+
f(42); // OK: calls #2. (#1 is not a viable candidate: type deduction
|
| 84 |
+
// fails[temp.deduct] because A<int>::~A() is implicitly used in its
|
| 85 |
+
// decltype-specifier)
|
| 86 |
+
}
|
| 87 |
+
template<class T> auto q(T)
|
| 88 |
+
-> decltype((h<T>())); // does not force completion of A<T>; A<T>::~A() is not implicitly
|
| 89 |
+
// used within the context of this decltype-specifier
|
| 90 |
+
void r() {
|
| 91 |
+
q(42); // error: deduction against q succeeds, so overload resolution selects
|
| 92 |
+
// the specialization ``q(T) -> decltype((h<T>()))'' with T=int;
|
| 93 |
+
// the return type is A<int>, so a temporary is introduced and its
|
| 94 |
+
// destructor is used, so the program is ill-formed
|
| 95 |
+
}
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
— *end example*]
|
| 99 |
+
|