Structured bindings were introduced in c++17 as an easier way of getting data out of std::pair
, std::tuple
and the map
containers. They are also quite handy to extract data from simple data aggregates, here is an example using the ubiquitous x,y Point struct
#include <iostream>
#include <type_traits>
struct Point
{
int x = 1;
int y = 1;
};
int main()
{
Point point;
auto [x, y] = point;
std::cout << std::boolalpha << std::is_same_v<int, decltype(x)>;
}