Binding

In this lesson, we will list down the different initializers which support structured binding.

Initializers That Support Structured Bindings

Structured Binding is not only limited to tuples, we have three cases from which we can bind from:

1. If the initializer is an array:

Press + to interact
#include <iostream>
int main() {
// works with arrays:
double myArray[3] = { 1.0, 2.0, 3.0 };
auto [a, b, c] = myArray;
std::cout << a << " " << b << " " << c;
}

In this case, an array is copied into a temporary object, and a, b and c refers to copied elements from the array.

The number of identifiers must match the number of elements in the array.

2. If the initializer supports std::tuple_size<>, provides ...