| As someone who wrote a lot of C and legacy C++, I find the first form easier to understand. The "int i=0; ... ++i" part is just your typical C-style loop. And the "auto&& it: vec" is the for-each kind of loop that dates back from C++11. The only new thing is that you can do both at the same time, which is not much of a stretch. On the second one, I had to look up what the "std::views::enumerate" did. It is kind of obvious when you look at the code, but it is not as explicit. And maybe most importantly, it doesn't do the same thing! The first loop starts at one, you can tell because it is ++i, not i++. A debatable choice when it comes to readability, but you can see it right before your eyes. For the second loop, I had to, again, look up to make sure the result of "std::views::enumerate" was indeed zero-indexed (and it is, of course). Which form you prefer depends on if you like being explicit or if you prefer abstractions. I usually prefer the former. Performance-wise, the generated code is probably very close, but the first one is likely to have an advantage on debug (unoptimized) builds. |