The C++20 version is still clearly inferior to the Python and Lua examples because you still have to manually increment the counter in the loop body. IMO the sibling comment by HarHarVeryFunny has a much better C++ equivalent for this idiom, even if it's slightly more verbose.
The C++20 version is still clearly inferior to the Python and Lua examples because you still have to manually increment the counter in the loop body. IMO the sibling comment by HarHarVeryFunny has a much better C++ equivalent for this idiom, even if it's slightly more verbose.
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);