468,513 Members | 1,506 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.

iterator vs const_iterator

whats the difference - apart from what the name suggests? - i.e. one is
const

What are there pros and cons of using one over the other ?

Jul 21 '06 #1
3 28744
Bit byte wrote:
whats the difference - apart from what the name suggests? - i.e. one
is const

What are there pros and cons of using one over the other ?
http://www.aristeia.com/Papers/CUJ_June_2001.pdf

And check out the rest: http://www.aristeia.com/publications.html

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 21 '06 #2
Bit byte wrote:
whats the difference - apart from what the name suggests?
- i.e. one is const
It isn't const. It's used to access an element of a container as constant.
What are there pros and cons of using one over the other ?
Pretty much the same as with any other use of constants.
The advantage of the regular iterator is that you can modify objects through
it. The advantage of the const_iterator is that you can use it to access
elements of a container that is const.

Jul 21 '06 #3
Bit byte wrote:
whats the difference - apart from what the name suggests? - i.e. one is
const

What are there pros and cons of using one over the other ?
Hi,
const_iteratoer means that within the iterator the container is const and
all of its elements are const. With a const_iterator you can neither modify
the container(add/remove elements) nor can you modify the elements in that
container. The advantage of the const_iterator is that the compiler
produces faster code when you use it. So you should use the const_iterator
whenever you iterate over the container without modifying anything.

Regards
Thorsten

Jul 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by john smith | last post: by
8 posts views Thread by Alexander Stippler | last post: by
1 post views Thread by quantdev2004 | last post: by
reply views Thread by nick | last post: by
5 posts views Thread by John Harrison | last post: by
1 post views Thread by flopbucket | last post: by
reply views Thread by mailforpr | last post: by
2 posts views Thread by Markus Dehmann | 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.