ul said:
Hello,
Just wonder what is faster for std::vector, const_iterator od iterator?
Or is this stl-realisation-dependent?
Formally:
a) it depends on the STL implementation.
b) both are random access iterators and have the same performance
guarantees. But that does not say that constant time operations take the
same time for both.
That said, a typical implementation for iterators into a std::vector should
not be more than a little wrapper around a single pointer and iterator
movements will be just translated into pointer arithmetic. Thus, both
versions should be equally fast. However, using the const_iterator may help
the compiler to do some optimizations in functions that are passed the
reference object of the iterator.
Best
Kai-Uwe Bux