P3817 — abstract

◀ back to the paper

Structured bindings today

Declaration — and nothing else

The values live in a hidden object

Given

auto [a, b] = f();

Expands to

auto __e_today = f();

a and b name pieces of __e_today, and both are new names.

Declaration Example

Given

Point arr[2];
auto& [x, y] = arr;

Expands to

Point (&__e_today)[2] = arr; // __e_today references arr
Point& x = __e_today[0];     // x is declared as a reference to __e_today[0]
Point& y = __e_today[1];     // y is declared as a reference to __e_today[1]

Assign, don’t declare

using marks an element that names an existing variable — it is assigned, not declared.

Given

int id;
auto [using id, name] = get_record(); // id is assigned, name is declared

Assignment Example

Given

Point arr[2];
Point x;
auto& [using x, y] = arr;

Expands to

Point (&__e_p3817)[2] = arr; // __e_p3817 references arr, no change
x = __e_p3817[0];            // x is assigned from __e_p3817[0]
Point& y = __e_p3817[1];     // y is declared as a reference to __e_p3817[1]