| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Bit byte" |
| Date: |
21 Jul 2006 09:10:07 AM |
| Object: |
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 ?
.
|
|
| User: "Rolf Magnus" |
|
| Title: Re: iterator vs const_iterator |
21 Jul 2006 09:20:46 AM |
|
|
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.
.
|
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: iterator vs const_iterator |
21 Jul 2006 09:09:41 AM |
|
|
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
.
|
|
|
|
| User: "Thorsten Kiefer" |
|
| Title: Re: iterator vs const_iterator |
21 Jul 2006 10:50:59 AM |
|
|
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
.
|
|
|
|

|
Related Articles |
|
|