I get, abstraction is to make programmers' life easier, but to go to the point that you need to abstract a for loop?
But that is not at all what ranges are about. Also note that the loop in the code example is not really an abstraction. Well... it is, like every for loop, like the entire language... but the point is, this is really just a combination of standard language features (auto and range-based for), and a good one.
Yes, I know he wasn't talking about abstracting the 'for' loop per se.
As for all other advantages you mentioned (which I don't know why people see a critique as a reason to start a flame war of C-ish vs C++ style), you can also achieve using a 'while' loop. I never mentioned that one should not use a class in a loop. My critique was regarding the first post, as I emphatized more than once, as the user (of other forum) stated that using a class is 1) lighter and 2) less error prone than 'normal' loops:
normal for loops are too heavy, too error prune...
It's FINE to use a class, what is not fine is to teach beginners that using classes are magic solutions that will solve all your problems (anti-pattern). Not just that, but if the implementation of the class is somehow wrong, it just makes much more difficult to track a bug (contrary of what you said in your last paragraph), because it's less obvious if the problem is with the iterator implementation or the code running outside/inside the loop. And I think @Hodgman explained very well the reason I mean:
And sure that's smaller, cleaner, simpler... but I do actually believe that this smaller version is harder to fully understand than the first version because it's moved the actual mechanism elsewhere. When doing this kind of work, I prefer the concrete bitwise details to be front of mind, not obfuscated.
And don't relie on -O3 (good luck if you do). Not just it is a source of grotesque bugs, reordering and jumping operations, as it will make even harder to track those bugs. Linux kernel has often reported bugs that were introduced in the modules when compiling the using optimization.