Range Based for loop vs iterator for STL Containers
-
wrote on 23 Feb 2022, 15:33 last edited by
Hi All,
Like to know when to prefer, range based for loop vs iterators for STL Containers.
Any pointers on advantage and disadvantages of both method would be also helpful.
Thanks!
-
wrote on 23 Feb 2022, 21:19 last edited by Kent-Dorfman
range based for loops cannot modify the length of the container. iterators facilitate adding or deleting elements.
-
range based for loops cannot modify the length of the container. iterators facilitate adding or deleting elements.
wrote on 24 Feb 2022, 06:50 last edited by@Kent-Dorfman : Thanks for the input.
If we are not going to modify the container, then which one provide better performance ? -
@Kent-Dorfman : Thanks for the input.
If we are not going to modify the container, then which one provide better performance ?@Vinoth-Rajendran4 said in Range Based for loop vs iterator for STL Containers:
If we are not going to modify the container, then which one provide better performance ?
not using STL Containers
-
@Vinoth-Rajendran4 said in Range Based for loop vs iterator for STL Containers:
If we are not going to modify the container, then which one provide better performance ?
not using STL Containers
wrote on 24 Feb 2022, 07:15 last edited by@J-Hilk : for STL Container
-
@J-Hilk : for STL Container
@Vinoth-Rajendran4 the only real way to know is benchmarking it.
-
@Vinoth-Rajendran4 the only real way to know is benchmarking it.
wrote on 24 Feb 2022, 08:14 last edited by@J-Hilk : Thanks for the test suite link.
1/7