Unpacks compound values into named variables with an initialiser.

Pairs and tuples:

auto [x, y] = std::pair<int, int>{1, 2};
auto [name, job, age] = std::tuple<std::string, std::string, int>{"alice", "nurse", 30};

Getting key and value from a map:

for (auto& [key, val] : my_map) {
  std::cout << key << ": " << val << '\n';
}

Warning

C++ bindings are copies by default. Use auto& to avoid copying every element. Use const auto& when mutation isn't needed.

References