473,378 Members | 1,478 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,378 software developers and data experts.

list::iterator behavior (after insert/delete) specification

where is the behavior of list::iterator specified? I need to keep track
of ranges of data, all I can figure out so far is that iterators are
guaranteed to be valid unless you remove the elements they point to.

Example -- if L is a list and Li = L.end(), and you call
L.push_back(something), how do you know whether Li will still point to
the list's end, or whether it will point to the something?

I tried this program in Microsoft VC++ 6.0 and it looks like if Li is
assigned to L.end(), it will always point to L.end() in the face of
insertions. This happens to be the behavior I'm looking for, in one
case, but how do I know this is portable to other implementations of
list<?

#include <stdio.h>
#include <list>

typedef std::list<intL_t;

void print(L_t::iterator start, L_t::iterator stop, char *tag)
{
printf("%s", tag);
while (start != stop)
{
printf(" %d", *start);
++start;
}
printf("\n");
}

int main(int argc, char* argv[])
{
L_t the_list;

L_t::iterator a, b, c, d;

the_list.push_back(1);
the_list.push_back(2);
the_list.push_back(3);
a = the_list.begin();
b = the_list.end();
c = b; c--;
print(a,b,"a to b:");
print(a,c,"a to c:");
the_list.push_back(4);
print(a,b,"a to b:");
print(a,c,"a to c:");

return 0;
}

==== output when I run it ====
a to b: 1 2 3
a to c: 1 2
a to b: 1 2 3 4
a to c: 1 2

Aug 31 '06 #1
6 3688
Jason S wrote:
where is the behavior of list::iterator specified?
In the language Standard document.
I need to keep
track of ranges of data, all I can figure out so far is that
iterators are guaranteed to be valid unless you remove the elements
they point to.
Pretty much. What else do you need to know? The list iterators are
bidirectional, so you should also look at the traits of bidirectional
iterators (and the requirements for them).
Example -- if L is a list and Li = L.end(), and you call
L.push_back(something), how do you know whether Li will still point to
the list's end, or whether it will point to the something?
None of the valid list iterators change when you insert, right? So,
if you obtained the end (and held onto it), it won't change.
I tried this program in Microsoft VC++ 6.0 and it looks like if Li is
assigned to L.end(), it will always point to L.end() in the face of
insertions. This happens to be the behavior I'm looking for, in one
case, but how do I know this is portable to other implementations of
list<?
It is, AFAICT by reading the Standard.
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 31 '06 #2
Victor Bazarov wrote:
Jason S wrote:
where is the behavior of list::iterator specified?

In the language Standard document.
thanks. we have an old copy of the standard (1998?) at my company so I
guess we'll have to get an update.

sigh. what about the average person, why do they have to spend $300 to
get the standard to find out how the STL is supposed to be have, & why
doesn't this fact seem to be mentioned in any compiler/STL documents?

Sep 1 '06 #3
Jason S wrote:
Victor Bazarov wrote:
>Jason S wrote:
>>where is the behavior of list::iterator specified?

In the language Standard document.

thanks. we have an old copy of the standard (1998?) at my company so I
guess we'll have to get an update.
You probably should, it's not that expensive, but in 2003 nothing (IIRC)
changed in the way iterators or list are defined.
sigh. what about the average person, why do they have to spend $300 to
get the standard to find out how the STL is supposed to be have, & why
doesn't this fact seem to be mentioned in any compiler/STL documents?
I'm an average person and I spend about $18 once in five years to get
an electronic version of the Standard. You could also get (and I
strongly recommend it) draft versions from the Standard Committee page
(predictable) and updated books on the language and the library (not
very predicatble).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 1 '06 #4
I'm an average person and I spend about $18 once in five years to get
an electronic version of the Standard.
thanks, I didn't realize there were electronic copies... looks like
those are now $30 & you can print them out.
http://webstore.ansi.org/ansidocstor...IEC+14882-2003
http://webstore.ansi.org/ansidocstore/about.asp

Sep 1 '06 #5
Jason S wrote:
>I'm an average person and I spend about $18 once in five years to get
an electronic version of the Standard.

thanks, I didn't realize there were electronic copies... looks like
those are now $30 & you can print them out.
http://webstore.ansi.org/ansidocstor...IEC+14882-2003
http://webstore.ansi.org/ansidocstore/about.asp
I don't know why you would. I refer to mine frequently, but always use
the electronic PDF.
Sep 1 '06 #6
Jason S wrote:
>I'm an average person and I spend about $18 once in five years to
get
an electronic version of the Standard.

thanks, I didn't realize there were electronic copies... looks like
those are now $30 & you can print them out.
http://webstore.ansi.org/ansidocstor...IEC+14882-2003
http://webstore.ansi.org/ansidocstore/about.asp
If you want it printed, you can get that here for $63.75

http://www.amazon.com/gp/product/047...948032?ie=UTF8
It is the British edition, with identical content.
Bo Persson
Sep 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: sam | last post by:
Hi, This is a "list iterator" problem I expect it will copy the list iterator (l_iter) to the caller: eg. list<HashMap>::iterator AcctConfParser::find_Acct_rule(string i) {...
2
by: Flwz | last post by:
There's something I don't quite understand, sorry if that sound stupid or whatever ; ) why is : for( it = Flare::flareList.begin() ; it != Flare::flareList.end(); it++) if (it->isWorn()) {...
15
by: sandwich_eater | last post by:
I want to know how to set an std::list iterator variable to make it null or nil. If this is not possible what is the value of an uninitialised std::list iterator and is it ok to assign this value...
8
by: freckred76 | last post by:
Hi, I think this might be a VC++ problem. I am using Microsoft Visual Studio 2005 Full Version (8.0). I have a simple for loop that iterates over a list using the standard iterator. The...
3
by: Amit Bhatia | last post by:
User-Agent: OSXnews 2.081 Xref: number1.nntp.dca.giganews.com comp.lang.c++:818044 Hi, I am wondering if I can assign a list iterator = NULL. Suppose I have a class A: A.h class A{ //ctors...
15
by: jayesah | last post by:
Hi All, List and its iterator work as following way : list<intmylist; list<int>::iterator itr; itr = mylist.begin(); cout << (*itr); But I want something like this:
10
by: Drew | last post by:
I'm looking to add an element to list of items, however I'd like to add it at a specific index greater than the current size: list = list.insert(10,4) What I'd like to see is something like:
2
by: Rohit.MEHTA | last post by:
Hi All I want to overload the ++ and - operator for stl list iterator so that I could do some thing additional in that As want to set the current node status also Can some one please post...
1
by: David Bilsby | last post by:
All Apologies for cross posing this but I am not sure if this is a VC 8 STL bug or simply an invalid use of the iterator. I have a PCI card access class which basically abstracts a third party...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.