468,513 Members | 1,597 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

What is faster, const_iterator or iterator?

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

Aug 25 '06 #1
2 3882
ul wrote:
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
Aug 25 '06 #2

ul wrote:
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

Aug 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Tim Partridge | last post: by
5 posts views Thread by john smith | last post: by
3 posts views Thread by John | last post: by
12 posts views Thread by Steven T. Hatton | last post: by
5 posts views Thread by John Harrison | last post: by
10 posts views Thread by Yahooooooooo | last post: by
2 posts views Thread by subramanian100in | last post: by
16 posts views Thread by John Doe | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.