C++20 Improved the For-Loop Syntax
1 points
1 hour ago
| 1 comment
| lzon.ca
| HN
HarHarVeryFunny
56 minutes ago
[-]
C++20 also has an enumerate() generator, so if you like the python syntax you can just do:

for (auto [i,v] : std::views::enumerate(vec)) std::cout << i << ": " << v << std::endl;

FWIW C++23 also has a python-like print and println:

std::println("{}: {}", i, v);

reply