Otherwise,
Template:c
, where
Template:c
is looked up by
Template:rlp
only, ignoring non-ADL lookup.
In these initializer expressions,
Template:c
is an lvalue if the type of the entity
Template:ttb
is an lvalue reference (this only happens if the
Template:spar
is
Template:ttb
or if it is
Template:ttb
and the initializer expression is an lvalue) and an xvalue otherwise (this effectively performs a kind of perfect forwarding),
Template:c
is a
Template:c
prvalue, and
Template:c
is always interpreted as a template parameter list.
The variable has the same
Template:rlp
as
Template:ttb
.
The identifier then becomes the name of an lvalue that refers to the object bound to said variable.
The
referenced type
for the i-th identifier is
Template:c
.
Template:source
[
edit
]
Case 3: binding to data members
Every non-static data member of
Template:ttb
must be a direct member of
Template:ttb
or the same base class of
Template:ttb
, and must be well-formed in the context of the structured binding when named as
Template:tt
.
Template:ttb
may not have an anonymous union member. The number of identifiers must equal the number of non-static data members.
Each identifier in
Template:spar
becomes the name of an lvalue that refers to the next member of
Template:ttb
in declaration order (bit-fields are supported); the type of the lvalue is that of
Template:c
, where
Template:tt
refers to the i
Template:sup
member.
The
referenced type
of the i-th identifier is the type of
Template:c
if it is not a reference type, or the declared type of
Template:tt
otherwise.
Template:source
[
edit
]
Notes
Template:rrev
The lookup for member
Template:tt
ignores accessibility as usual and also ignores the exact type of the non-type template parameter. A private
Template:c
member will cause the member interpretation to be used, even though it is ill-formed.
The portion of the declaration preceding
Template:ttb
applies to the hidden variable
Template:ttb
, not to the introduced identifiers:
Template:source
The tuple-like interpretation is always used if
Template:c
is a complete type, even if that would cause the program to be ill-formed:
Template:source
The usual rules for reference-binding to temporaries (including lifetime-extension) apply if a
Template:spar
is present and the
Template:spar
is a prvalue. In those cases the hidden variable
Template:ttb
is a reference that binds to the temporary variable
Template:rlp
from the prvalue expression, extending its lifetime. As usual, the binding will fail if
Template:ttb
is a non-const lvalue reference:
Template:source
Template:c
, where
Template:tt
denotes a structured binding, names the
referenced type
of that structured binding. In the tuple-like case, this is the type returned by
Template:c
, which may not be a reference even though a hidden reference is always introduced in this case. This effectively emulates the behavior of binding to a struct whose non-static data members have the types returned by
Template:tt
, with the referenceness of the binding itself being a mere implementation detail.
Template:source
Template:rrev
Template:feature test macro
[
edit
]
Example
Template:example
[
edit
]
Defect reports
Template:dr list begin
Template:dr list item
Template:dr list item
Template:dr list item
Template:dr list item
Template:dr list item
Template:dr list item
Template:dr list end
[
edit
]
References
Template:ref std c++23
Template:ref std
Template:ref std end
Template:ref std c++20
Template:ref std
Template:ref std end
Template:ref std c++17
Template:ref std
Template:ref std end
[
edit
]
See also
Template:dsc begin
Template:dsc inc
Template:dsc end
Template:langlinks
Retrieved from "
https://en.cppreference.com/mwiki/index.php?title=cpp/language/structured_binding&oldid=150915
"
Toolbox