Which one gives a better performance in terms of std::vector iteration: the newly introduced C++11 for (auto &x: some_vector)
or for (vector<type>::iterator it=some_vector.begin(); it != some_vector.end(); it++)
method?
Asked
Active
Viewed 111 times
1

thesquaregroot
- 1,414
- 1
- 21
- 35

fnisi
- 1,181
- 1
- 14
- 24
-
and std::for_each with lambda expression. – cbel Apr 02 '14 at 03:03
-
1It should be ++it, and the speed should be similar for both, as the c++11 syntax is basically sugar for the second. The for_each with lambda may be slower, depending on your compiler and if it can inline the lambda function. – Eloff Apr 02 '14 at 03:06
-
The range based for loop also hoists the `end()` out of the loop. – Fred Larson Apr 02 '14 at 03:12