Topic: Reference to a moved STL collection element


Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Tue, 12 Jun 2001 21:13:39 GMT
Raw View
In article <Oe6V6.87039$Be4.28394168@news3.rdc1.on.home.com>, John Brown says...
>
>If I have a reference to an object that's sitting in some STL collection
>(not a pointer collection but the actual objects), and then the collection
>is resized (potentially moving the objects), is my reference still good? I
>know that iterators become undefined at this point but I'm fuzzy on what
>happens to a reference. Thanks.

That depends on the container. std::vector<> might invalidate
references, std::deque might (but not on insertions at either end),
and std::list, std::[multi]map and std::[multi]set never do.

HTH,
Michiel Salters

--
Michiel Salters
Consultant Technical Software Engineering
CMG Trade, Transport & Industry
Michiel.Salters@cmg.nl

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "John Brown" <nospam@nospam.com>
Date: Mon, 11 Jun 2001 18:27:20 GMT
Raw View
If I have a reference to an object that's sitting in some STL collection
(not a pointer collection but the actual objects), and then the collection
is resized (potentially moving the objects), is my reference still good? I
know that iterators become undefined at this point but I'm fuzzy on what
happens to a reference. Thanks.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]