Topic: Pointer invalidation in std::list<>


Author: kuyper@wizard.net (James Kuyper)
Date: Thu, 10 Jun 2004 21:00:18 +0000 (UTC)
Raw View
dietmar_kuehl@yahoo.com (Dietmar Kuehl) wrote in message news:<5b15f8fd.0406070439.3a312eba@posting.google.com>...
 > Dave <better_cs_now@yahoo.com> wrote:
 > > The Standard states that modifying operations on std::list<> don't
 > > invalidate iterators or references (except to removed elements, of course).
 >
 > I think this statement refers to all kinds of "references" to the object
 > which includes both pointers and C++ references.

I think the standard's inconsistent in it's explanation of
invalidation. In several other locations, the standard specifies that
invalidation of pointers and references, rather than using
"references" to cover both types:

23.1p10: StandardContainer::swap() invalidates neither pointers nor
references.
23.2.4.2p5: std::vector<>::reserve(): reallocation invalidates both.
26.3.2.6p3,8: std::valarry<>::computed assignment operators:
invalidates neither
26.3.2.7p9: std::valarray<>::resize(): invalidates both.


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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.jamesd.demon.co.uk/csc/faq.html                       ]





Author: dietmar_kuehl@yahoo.com (Dietmar Kuehl)
Date: Tue, 8 Jun 2004 14:11:55 +0000 (UTC)
Raw View
Dave <better_cs_now@yahoo.com> wrote:
> The Standard states that modifying operations on std::list<> don't
> invalidate iterators or references (except to removed elements, of course).

I think this statement refers to all kinds of "references" to the object
which includes both pointers and C++ references. Also, even if not, there
is no way to invalidate a pointer to an object while the reference stays
valid.

> I'd like to hear people's thoughts on whether or not it was the committee's
> intent that pointers also not be invalidated.  Is this on oversight or a
> deliberate omission?

I think it is neither an oversight nor a deliberate omission. It is, maybe,
unfortunate wording because reference in a C++ context may refer to two
different things: really just C++ references or all kinds of reference
which includes pointers and references.
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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.jamesd.demon.co.uk/csc/faq.html                       ]






Author: Dave <better_cs_now@yahoo.com>
Date: Sun, 6 Jun 2004 14:55:06 +0000 (UTC)
Raw View
Hello all,

The Standard states that modifying operations on std::list<> don't
invalidate iterators or references (except to removed elements, of course).
I'd like to hear people's thoughts on whether or not it was the committee's
intent that pointers also not be invalidated.  Is this on oversight or a
deliberate omission?

May I assume that elements in a std::list<> will remain at the same address
for their entire lifetime if I only do inserts and deletes?

Thanks,
Dave



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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.jamesd.demon.co.uk/csc/faq.html                       ]