Do const references in structured bindings extend the lifetime of the decomposed object?

Yes. The trick is to realize that despite the appearance, the portion of a structured binding declaration before the [ doesn’t apply to the names in the identifier-list. They apply instead to the variable introduced implicitly by the declaration. [dcl.struct.bind]/1: First, a variable with a unique name e is introduced. If the assignment-expression in the … Read more

Why can’t decomposition declarations be constexpr?

Question: why aren’t decomposition declarations be allowed to be constexpr? (apart from “because the Standard says so”). There is no other reason. The standard says in [dcl.dcl] p8: The decl-specifier-seq shall contain only the type-specifier auto (7.1.7.4) and cv-qualifiers. That means it can’t be declared with constexpr. This was the subject of a National Body … Read more

Can the structured bindings syntax be used in polymorphic lambdas

This is not currently allowed by the syntax; structured bindings are a simple-declaration: simple-declaration:[…] – attribute-specifier-seqopt decl-specifier-seq ref-qualifieropt [ identifier-list ] initializer ; while function parameters are introduced by a parameter-declaration-list, which contains declarators: The declarators specify the names of these entities and (optionally) modify the type of the specifiers with operators such as * … Read more

structured binding with [[maybe_unused]]

In the structure bindings paper: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0144r2.pdf they discuss their reasoning: 3.8 Should there be a way to explicitly ignore components? The motivation would be to silence compiler warnings about unused names. We think the answer should be “not yet.” This is not motivated by use cases (silencing compiler warnings is a motivation, but it is … Read more

Why do C++17 structured bindings not use { }?

The National Bodies from Spain and US have proposed to change back to the {} syntax because (P0488R0): The “structured bindings” proposal originally used braces “{}” to delimit binding identifiers. Those delimiters were changed to brackets “[]” under the assertion that they didn’t introduce any syntactic problem. However, they turned out to introduce syntactic ambiguity … Read more

std::ignore with structured bindings?

The structured bindings proposal contains a dedicated section answering your question (P0144R2): 3.8 Should there be a way to explicitly ignore components? The motivation would be to silence compiler warnings about unused names. We think the answer should be “not yet.” This is not motivated by use cases (silencing compiler warnings is a motivation, but … Read more

Lambda implicit capture fails with variable declared from structured binding

Core issue 2313 changed the standard so that structured bindings are never names of variables, making them never capturable. P0588R1’s reformulation of lambda capture wording makes this prohibition explicit: If a lambda-expression […] captures a structured binding (explicitly or implicitly), the program is ill-formed. Note that this wording is supposedly a placeholder while the committee … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)