Structured binding declaration (since C++17)
Binds the specified names to subobjects or elements of the initializer.
Like a reference, a structured binding is an alias to an existing object. Unlike a reference, a structured binding does not have to be of a reference type.
attr (optional) decl-specifier-seq ref-qualifier (optional) [ sb-identifier-list ] initializer ;
|
|||||||||
attr | - | sequence of any number of attributes | ||
decl-specifier-seq | - | sequence of the following specifiers (following the rules of simple declaration):
| ||
ref-qualifier | - | either & or &&
| ||
sb-identifier-list | - | list of comma-separated identifiers introduced by this declaration, each identifier may be followed by an attribute specifier sequence(since C++26) | ||
initializer | - | an initializer (see below) |
initializer may be one of the following:
= expression
|
(1) | ||||||||
{ expression }
|
(2) | ||||||||
( expression )
|
(3) | ||||||||
expression | - | any expression (except unparenthesized comma expressions) |
A structured binding declaration introduces all identifiers in the sb-identifier-list as names in the surrounding scope and binds them to subobjects or elements of the object denoted by expression. The bindings so introduced are called structured bindings.
One of the identifiers in the sb-identifier-list can be preceded by an ellipsis. Such an identifier introduces a structured binding pack. The identifier must declare a templated entity. |
(since C++26) |
A structured binding is an identifier in the sb-identifier-list that is not preceded by an ellipsis, or an element of a structured binding pack introduced in the same identifier list(since C++26).
Contents |