| View previous topic :: View next topic |
| Author |
Message |
Neelesh Bodas Guest
|
Posted: Mon Nov 28, 2005 2:33 pm Post subject: iterator beyond the first element |
|
|
C++ guarantees that there exists a valid iterator beyond the last
element of a container. However, such iterator might not be written or
dereferenced. This is also true for arrays - C++ gurantees that there
exists one position available beyond the end of array.
Does it give similar guarantee about the position before the first
element - the position indicated by the iterator rbegin()? (For arrays
as well as standard containers)
|
|
| Back to top |
|
 |
Neelesh Bodas Guest
|
Posted: Mon Nov 28, 2005 2:40 pm Post subject: Re: iterator beyond the first element |
|
|
Neelesh Bodas wrote:
| Quote: | the position indicated by the iterator rbegin()? (For arrays
as well as standard containers)
|
Typo. should be rend()
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Mon Nov 28, 2005 2:41 pm Post subject: Re: iterator beyond the first element |
|
|
Neelesh Bodas wrote:
| Quote: | C++ guarantees that there exists a valid iterator beyond the last
element of a container. However, such iterator might not be written or
dereferenced. This is also true for arrays - C++ gurantees that there
exists one position available beyond the end of array.
Does it give similar guarantee about the position before the first
element - the position indicated by the iterator rbegin()? (For arrays
as well as standard containers)
|
You are mistaken about at least one thing: 'rbegin()' returns an iterator
that points to the _last_ element, not first.
No, C++ does not guarantee the existence of "one-before-first" iterator
(in your terms it would be '--begin()').
V
|
|
| Back to top |
|
 |
Pete Becker Guest
|
Posted: Mon Nov 28, 2005 2:42 pm Post subject: Re: iterator beyond the first element |
|
|
Neelesh Bodas wrote:
| Quote: |
Does it give similar guarantee about the position before the first
element
|
No.
| Quote: | the position indicated by the iterator rbegin()?
|
rbegin() is completely different. Reverse iterators for containers use
the end() and begin() iterators and index one off from the iterator's
position.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
|
|
| Back to top |
|
 |
Sumit Rajan Guest
|
Posted: Mon Nov 28, 2005 2:42 pm Post subject: Re: iterator beyond the first element |
|
|
"Neelesh Bodas" <neelesh.bodas (AT) gmail (DOT) com> wrote
| Quote: | C++ guarantees that there exists a valid iterator beyond the last
element of a container. However, such iterator might not be written or
dereferenced. This is also true for arrays - C++ gurantees that there
exists one position available beyond the end of array.
Does it give similar guarantee about the position before the first
element - the position indicated by the iterator rbegin()? (For arrays
as well as standard containers)
|
If you have a copy of "The C++ Standard Library" close to you, please take a
look at Section 7.4.1. You will find a detailed explanation on this.
Regards,
Sumit.
--
Sumit Rajan <sumitr (AT) msdc (DOT) hcltech.com>
|
|
| Back to top |
|
 |
Neelesh Bodas Guest
|
Posted: Mon Nov 28, 2005 2:44 pm Post subject: Re: iterator beyond the first element |
|
|
Pete Becker wrote:
| Quote: | rbegin() is completely different. Reverse iterators for containers use
the end() and begin() iterators and index one off from the iterator's
position.
|
Yeah, that was a typo. And yes, I get what you are saying - you mean to
say that the logical position and physical position of reverse
iterators are different - they are one unit off - Is that right? If so,
My confusion is resolved.
|
|
| Back to top |
|
 |
Neelesh Bodas Guest
|
Posted: Mon Nov 28, 2005 2:45 pm Post subject: Re: iterator beyond the first element |
|
|
Sumit Rajan wrote:
| Quote: | If you have a copy of "The C++ Standard Library" close to you, please take a
look at Section 7.4.1. You will find a detailed explanation on this.
|
Thanks Sumit, Just opened Josuttis' Book. :-)
|
|
| Back to top |
|
 |
|