C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

iterator beyond the first element

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Neelesh Bodas
Guest





PostPosted: Mon Nov 28, 2005 2:33 pm    Post subject: iterator beyond the first element Reply with 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)

Back to top
Neelesh Bodas
Guest





PostPosted: Mon Nov 28, 2005 2:40 pm    Post subject: Re: iterator beyond the first element Reply with quote




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





PostPosted: Mon Nov 28, 2005 2:41 pm    Post subject: Re: iterator beyond the first element Reply with quote



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





PostPosted: Mon Nov 28, 2005 2:42 pm    Post subject: Re: iterator beyond the first element Reply with quote

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





PostPosted: Mon Nov 28, 2005 2:42 pm    Post subject: Re: iterator beyond the first element Reply with quote


"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





PostPosted: Mon Nov 28, 2005 2:44 pm    Post subject: Re: iterator beyond the first element Reply with quote


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





PostPosted: Mon Nov 28, 2005 2:45 pm    Post subject: Re: iterator beyond the first element Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.