Object in list invalidation question



 DEVELOP > c-Plus-Plus > Object in list invalidation question

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 25 Jan 2008 12:14:23 PM
Object: Object in list invalidation question
Hello,
Consider the following situation:
std::list <int> numbers;
numbers.push_back(5);
int * ptr = &(*(numbers.begin()));
// Work on the list
numbers.push_back(7);
numbers.push_back(12);
// etc.
My question is: will ptr always point to valid memory provided the
only operations performed on the list are to add to it (and ptr isn't
reassigned, etc)? Given the obvious implementation of a linked list,
then yes, but is it actually guaranteed (implicitly or otherwise) by
the standard?
Thanks!
.

User: "James Kanze"

Title: Re: Object in list invalidation question 25 Jan 2008 01:32:40 PM
On Jan 25, 7:14 pm,
wrote:

Consider the following situation:
std::list <int> numbers;
numbers.push_back(5);
int * ptr =3D &(*(numbers.begin()));
// Work on the list
numbers.push_back(7);
numbers.push_back(12);
// etc.
My question is: will ptr always point to valid memory provided the
only operations performed on the list are to add to it (and ptr isn't
reassigned, etc)? Given the obvious implementation of a linked list,
then yes, but is it actually guaranteed (implicitly or otherwise) by
the standard?

Yes, for std::list, std::set and std::map. (It isn't guaranteed
for other container types.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER