Structured binding — decompose objects into named variables.
1#include <tuple>2#include <map>34// Array5int arr[] = {1, 2, 3};6auto [a, b, c] = arr;78// Pair/Tuple9std::pair<int, std::string> p = {1, "hello"};10auto [id, name] = p;1112// Struct13struct Point { int x; int y; };14Point pt = {10, 20};15auto [x, y] = pt;1617// Map iteration18std::map<std::string, int> scores = {{"Alice", 95}, {"Bob", 87}};19for (const auto& [name, score] : scores) {20 std::cout << name << ": " << score << "\n";21}2223// In if statements24if (auto [it, inserted] = scores.insert({"Charlie", 90}); inserted) {25 std::cout << "Inserted\n";26}
Requirements: