Topic: Definition of valid/invalid iterators
Author: look@sig.please.because.this.is.invalid.bhp.com.au (Chris Kuan)
Date: 2000/07/20 Raw View
smeyers@aristeia.com (Scott Meyers) wrote in comp.std.c++:
>The notion of what it means for an iterator to be "valid" or "invalid" is a
>tricky one, in my experience.
> In article <MPG.12b7a174f83ea1b989707@news.teleport.com>,
> Scott Meyers <smeyers@aristeia.com> wrote:
>
> > - I don't understand what it means to invalidate an iterator. Could it
> > mean that my iterator continues to point to the same element it did
> > before, but all bets are off about what elements I'll see if I continue
> > my traversal of the hash table?
>
> Yes. But that doesn't invalidate the iterator -- you can still
> dereference it and get the same element you did before.
>I've since discussed with several people how the notion of an "invalidated"
>iterator is not terribly well defined, yet it's crucial to effective use of
>the STL. It has been suggested that the lack of a definition in the
>standard is worthy of a defect report. Comments?
ISTM you have two distinct notions of validity - current, vs. future. For me,
the "natural" concept of an iterator is that its validity is assured for its
entire lifetime. Therefore invalidation also negates an iterator's currency.
ark stated that this is not so, and I can see his point.
How more ineffective do you think the STL would become if invalidation
guaranteed undefined behaviour for existing iterators?
--
Chris Kuan, CSC Technology Services, formerly BHP Information Technology
Concatenate for email: mr gazpacho @ hotmail . com
"Law is a repository for the aimlessly clever" - Tim Freedman
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]