Modifiers & Limitations
To further specify the nature of our structured bindings, we can use modifier types.
We'll cover the following...
Several modifiers can be used with structured bindings.
const modifiers:
const auto [a, b, c, ...] = expression;
References:
auto& [a, b, c, ...] = expression;auto&& [a, b, c, ...] = expression;
For example:
C++ 17
#include <iostream>using namespace std;int main() {std::pair a(0, 1.0f);auto& [x, y] = a;x = 10; // write accessstd::cout << a.first;// a.first is now 10}
In the example, x binds to the element in the generated object, that is a reference to a.
Now it’s also quite easy to get a reference to a tuple member: ...
Ask