Logo

Programming-Idioms

History of Idiom 13 > diff from v57 to v58

Edit summary for version 58 by programming-idioms.org:
New Cpp implementation by user [programming-idioms.org]

Version 57

2019-08-02, 18:47:28

Version 58

2019-08-05, 16:37:33

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Illustration

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Illustration
Extra Keywords
table dictionary hash traverse traversal
Extra Keywords
table dictionary hash traverse traversal
Imports
#include <iostream>
Code
for (const auto& [key, value]: mymap) {
	std::cout << "Key: " << key << " Value: " value << '\n';
}
Comments bubble
The [key, value] syntax is a structured binding declaration, since C++17.

'\n' doesn't flush stdout.
Doc URL
https://en.cppreference.com/w/cpp/language/structured_binding