Use preincrement with iterators

This tip submitted by Dirk Tjantele on 2010-09-06 07:55:37. It has been viewed 8113 times.
Rating of 3.9 with 65 votes



When using the unary operators ++ and -- on an STL interator, use the pre-increment and pre-decrement versions. This will run faster than the post-increment versions as it will avoid the need to hold on to a copy of the old state of the iterator to return.



More tips

Help your fellow programmers! Add a tip!