Wednesday, July 28, 2010

For Loop Iterators

The for loop end criterion with an STL iterator can use the '<' operator instead of the '!=' operator only if the STL iterator is a random access iterator.

It is recommended to always use '!=' for consistency, and for the small chance that someone changes to a container that does not have a random access iterator.

Reference: "The C++ Standard Library" by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 257.

No comments:

Post a Comment