Let v
be a std::vector<int>
. Which of the two methods below is faster for iterating over its elements?
for (auto& el: v) {...el...}
or
for (size_t i = 0; i < v.size(); ++i) {...v[i]...}
I'm seeing the former in a lot of competitive programming solutions, however I don't get how it can be faster than the one below unless the vector objects are something different from a built-in type