In your specific example, they are equivalent. And since they are equivalent, you naturally want to prefer the shortest version, which will also be the least error prone - for free.
In addition, it is proposed to reduce the range, as well as:
for ( var : range )
where var will be of type auto&& (aka forwading / universal reference), which is the best way to refer to an object. Just auto var will make a copy of each element, which may not be cheap. Unfortunately, he did not pass.
As a rule, you do not work with iterators directly, so you should be your first choice. Explicit iterators can also point to elements out of range, since you can move freely in a range, which leads to undefined behavior.
source share