Topic: What happens when an iterator precondition is violated?


Author: smeyers@aristeia.com (Scott Meyers)
Date: 1999/05/18
Raw View
My original question was simple: what happens if you try to pop an empty
std::stack?  I looked up the semantics of pop, and they're the same as
pop_back on a sequence.  So I looked up the semantics of pop_back, and
they're defined in terms of --end() on the sequence implementing the stack.
So I looked up the semantics of predecrement for bidirectional iterators,
and table 75 makes clear that it's a precondition of predecrement that
there be an element prior to the current one.  When a stack is empty, this
precondition is false.  So here's my revised question: what does the
standard say about the result of violating a precondition of an iterator
operation?  My guess is that the result is undefined, but I can't find that
in the standard.  I suspect I just don't know where to look.

Thanks,

Scott

--
Scott Meyers, Ph.D.                  smeyers@aristeia.com
Software Development Consultant      http://www.aristeia.com/
Visit http://meyerscd.awl.com/ to demo the Effective C++ CD


[ 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              ]






Author: Joerg Barfurth <jbarfurth@vossnet.de>
Date: 1999/05/18
Raw View
Scott Meyers wrote:
> =

[snip]
> precondition is false.  So here's my revised question: what does the
> standard say about the result of violating a precondition of an iterato=
r
> operation?  My guess is that the result is undefined, but I can't find =
that
> in the standard.  I suspect I just don't know where to look.
> =

IMHO this is covered by 17.4.3.7 and/or 17.4.3.8. I'm not sure whether th=
is
would count as an out-of-range argument (17.4.3.7) or as a violated
requirement (17.4.3.8).
The resulting behaviour should be undefined in either case.

-- J=F6rg Barfurth
---
[ 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              ]





Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/05/18
Raw View
Scott Meyers wrote:

> So I looked up the semantics of predecrement for bidirectional iterators,
> and table 75 makes clear that it's a precondition of predecrement that
> there be an element prior to the current one.

I guess you want to have a look at 17.4.3.7 [lib.res.on.arguments].

--

Valentin Bonnard


[ 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              ]