469,645 Members | 1,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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)

Nov 28 '05 #1
6 1929

Neelesh Bodas wrote:
the position indicated by the iterator rbegin()? (For arrays
as well as standard containers)


Typo. should be rend()

Nov 28 '05 #2
Neelesh Bodas wrote:

Does it give similar guarantee about the position before the first
element
No.
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)
Nov 28 '05 #3

"Neelesh Bodas" <ne***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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 <su****@msdc.hcltech.com>
Nov 28 '05 #4

Pete Becker wrote:
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.

Nov 28 '05 #5
Neelesh Bodas wrote:
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
Nov 28 '05 #6
Sumit Rajan wrote:
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. :-)

Nov 28 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by akush | last post: by
26 posts views Thread by Michael Klatt | last post: by
7 posts views Thread by Prawit Chaivong | last post: by
18 posts views Thread by silversurfer | last post: by
15 posts views Thread by Boltar | last post: by
5 posts views Thread by subramanian100in | last post: by
5 posts views Thread by Luis Zarrabeitia | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.