473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 2053

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: akush | last post by:
Hello!! i try to create a pointer on an iterator for a vector list ( with more than one values ). But if i iterate i only get the first value. if i want to get the next the program crahes. what...
26
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
7
by: Prawit Chaivong | last post by:
Hi, gurus Is it safe to do this in function? 'return &(*iterator)'; And iterator is std::set<something>::iterator Regards,
18
by: silversurfer | last post by:
Ok, this should be fairly easy for most of you (at least I hope so), but not for me: Let us say we have got the following elements: std::vector<Entry> models; //Entry is a struct...
15
by: Boltar | last post by:
Hi I'm going through an STL list container using a reverse iterator but it seems the erase() method only accepts ordinary iterators. Is there a similar method that will accept reverse iterators...
3
by: Belebele | last post by:
I have an Element class which is abstract and I would like to have an object of the Iterator class to iterate over a range of elements. I would like to use std::for_each to instrument the...
3
by: JurgenvonOerthel | last post by:
I want to replace one element in a list<stringby a list<stringand I need to obtain an iterator to the first element in the inserted list. In code: void...
5
by: subramanian100in | last post by:
Whenever we specify an iterator range to a container operation or an std::algorithm, the first iterator should always be a valid iterator ie it should point to some element in the respective...
5
by: Luis Zarrabeitia | last post by:
Hi there. For most use cases I think about, the iterator protocol is more than enough. However, on a few cases, I've needed some ugly hacks. Ex 1: a = iter() # assume you got the iterator...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.