Consider the following example (available here on Compiler Explorer), matching the 3 scenarios of structured-binding:
{ // array
auto value = std::array{ 1, 2 };
auto & [ v1, v2 ] = value;
static_assert(std::same_as<int, decltype(v1)>);
}
{ // tuple
auto value = std::tuple{ 1, 2 };
auto && [ v1, v2 ] = std::move(value);
static_assert(std::same_as<int, decltype(v1)>);
}
{ // user-defined type
struct toto{ int i; char c; };
const auto value = toto{ 1, 2 };
auto && [ v1, v2 ] = value;
static_assert(std::same_as<const int, decltype(v1)>);
}
I have troubles understanding why cv-qualifiers are propagated to the identifiers, but not the ref-qualifiers.
In the example above, I feel like it is kind of counter-intuitive that v1 is a possibly const-qualified int, but never ref-qualified.
What am I missing?