What is a concise notation for a range based for loop iterating over a few tuples

  • A+

Is there a simpler (shorter) way to write this code snippet as a loop:

for (auto [a, b]: {pair<int, int>{1, 2}, pair<int, int>{3, 4}})   foo(a, b); 

Preferably making the initializer list as close as possible to this form, which doesn't compile:

for (auto [a, b]: {{1, 2}, {3, 4}})   foo(a, b); 


You might do the following in C++17 thanks to deduction guide:

for (auto [a, b]: {std::pair{1, 2}, std::pair{3, 4}})     foo(a, b); 

or even

for (auto [a, b]: {std::pair{1, 2}, {3, 4}})     foo(a, b); 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: