This answer to this popular question gives the idiomatic use of a range-for loop with a map:
for (auto& kv : myMap) {
// do stuff, where kv.first is the key and kv.second is the value
}
the thing is, it's usually the case that we want to have meaningful names for the key and the value (and not so much for their pair). That means writing, for example:
for (auto& kv : myMap) {
auto planet_name = kv.first;
auto distance_from_sun = kv.second;
// do stuff with planet_name and distance_from_sun
}
and, well, you know - I don't want to write those entire three lines, especially since I don't care about kv (usually). I would expect something like
for (auto& {planet_name, distance_from_sun} : myMap) {
// do stuff with planet_name and planet_distance_from_sun
}
or
for (tie{auto& planet_name,auto& distance_from_sun} : myMap) {
// do stuff with planet_name and planet_distance_from_sun
}
or some other similar construction to work. If we can assign pairs, and if we can construct pairs when emplacing them in maps, why not be able to define pairs in a ranged for loop?
... or maybe C++11/14/17 does have some kind of trick for achieving this effect somehow?