C ++ - STL Vector :: const_iterator, why not use <xx.end ()?
2 answers
operator< defined only for random access iterators . They are provided, for example, by the std::vector and std::string containers, which, in essence, store their data in continuous storage, where iterators are usually slightly larger than wrapped pointers. The iterators provided by std::list , for example, are bidirectional iterators that provide only comparisons for equality.
Traditionally, as defensive programming, use < instead of != . In case of errors (for example, someone changes ++i to i+=2 ), the cycle will end even if the exact final value is never reached. However, another view of this is that it can mask the error, while a loop that runs endlessly or causes failures will make the error obvious.
+8