What is faster, const_iterator or iterator?

U

ul

Hello,

Just wonder what is faster for std::vector, const_iterator od iterator?
Or is this stl-realisation-dependent?
Target compilator gcc platform is Linux.

Thanks
 
K

Kai-Uwe Bux

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
 
P

peter koch

ul said:
Hello,

Just wonder what is faster for std::vector, const_iterator od iterator?
Or is this stl-realisation-dependent?
Target compilator gcc platform is Linux.

Thanks

This is implementation defined, but i would be extremely surprised if
there would be any difference between the two. IF there is a
difference, it will be a constant factor.

/Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top