Topic: The description of list operations in standard should be more concrete?
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/12/05 Raw View
Vlad Harchev wrote:
>
> In CD2 the description of most list operations [lib.list.ops] doesn't
> mention
> that the iterators to the contents of the list should be valid after such
> operations. But IMO most STL implementations (and the original one) leave
> all iterators to the list's elements valid (i mean 'all iterators' for
> nondestructive operations and and iterators to those elements, for which
> destructor
> is not called for other operations).
> Why don't make the standard more restrictive in this respect - IMO it should
> require that all operations mentioned in [lib.list.ops] should preserve the
> validity of iterators and references to the contents of the list (except to
> removed elements).
You've got the style of description backward. The standard states which
operations invalidate iterators, and the pointers and references derived
from them. By implication, the other operations don't invalidate them.
Incidentally, the general container requirements don't say which
operations invalidate iterators, but several of the standard containers
have operations that invalidate them. I think that the implication is
that if you are using an unknown container type (i.e. through a template
parameter), the only safe assumption is that any non-const operation on
the container invalidates all iterators, pointers, and references. Is
this correct?
[ 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: "Vlad Harchev" <vladhar@imimail.ssau.ru>
Date: 1998/12/07 Raw View
James Kuyper wrote in message <3668A32D.863939B0@wizard.net> ...
>You've got the style of description backward. The standard states which
>operations invalidate iterators, and the pointers and references derived
>from them. By implication, the other operations don't invalidate them.
>
>Incidentally, the general container requirements don't say which
>operations invalidate iterators, but several of the standard containers
>have operations that invalidate them. I think that the implication is
>that if you are using an unknown container type (i.e. through a template
>parameter), the only safe assumption is that any non-const operation on
>the container invalidates all iterators, pointers, and references. Is
>this correct?
In [lib.list.ops] only list-specific operations are listed, such as
reverse, sort, merge, remove_If, unique, splice. So I think that no
implications work. Note also, that stating "no other iterators are
invalidated" also means no ctors and dectors are called during this
operation for list container - this may be more important for somebody, than
preserving the validity of iterators/references.
- Vlad
[ 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: "Vlad Harchev" <vladhar@imimail.ssau.ru>
Date: 1998/12/04 Raw View
In CD2 the description of most list operations [lib.list.ops] doesn't
mention
that the iterators to the contents of the list should be valid after such
operations. But IMO most STL implementations (and the original one) leave
all iterators to the list's elements valid (i mean 'all iterators' for
nondestructive operations and and iterators to those elements, for which
destructor
is not called for other operations).
Why don't make the standard more restrictive in this respect - IMO it should
require that all operations mentioned in [lib.list.ops] should preserve the
validity of iterators and references to the contents of the list (except to
removed elements).
- Vlad
[ 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 ]