This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Advice on iterator vs. index efficiency
- From: Neal Becker <ndbecker2 at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 05 Oct 2007 13:27:07 -0400
- Subject: Advice on iterator vs. index efficiency
Based on advice from some time back, I write algorithms to use iterators
rather than index-based loops. Often, this requires jumping through
considerable hoops.
I'm just wondering, with current gcc loop optimizations, it this advice
still relevant? For example:
< iterator style loop >
for (; i != end (container); ++i)
do something with (*i);
< index style loop >
for (int i = 0; i < size (container); ++i)
do something with container[i];
Is there (in general) a difference in speed for these 2 styles? What about
if the containers are multi-dimensional and loops are nested?