Topic: Container iterators
Author: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
Date: 1997/02/24 Raw View
Hi,
the "Container requirements" section seems to say very little about
container iterators. IMO several important things are missing. In
particular, I suggest to add the following:
1) For a container type X, X::iterator is convertable to
X::const_iterator.
I couldn't find this guarantee even for the standard containers. Is this
an oversight? BTW, it would be nice if for reversible containers
X::reverse_iterator was convertable to X::const_reverse_iterator, too,
but this would require a change in the reverse_iterator spec, I think.
2) X::iterator and X::const_iterator must be of the same category.
This is IMO particularily important in the presence of algorithms
overloaded on iterator tags.
3) iterator_traits<X::iterator>::reference must be the same as
X::reference.
This is an issue only if reference classes are to be allowed ( which is
the case, I believe: see the vector<bool> thread ).
4) This one is actually a question: which functions short of swap and
assignment might invalidate iterators into the container? IMO the
standard should specify this. BTW, if begin and end are not allowed to
invalidate iterators I don't understand why X::iterator isn't required
to be at least of the forward iterator category.
Bye
Roman
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]