Topic: Defect Report: Unnecessary restriction on past-the-end iterators
Author: jpotter@falcon.lhup.edu (John Potter)
Date: 2000/02/04 Raw View
On 3 Feb 2000 17:29:40 GMT, scleary@jerviswebb.com wrote:
: Unnecessary restriction on past-the-end iterators
:
: Section: 24.1 [Iterator requirements]
: Submitter: Stephen Cleary
: Date: 02 February 2000
:
: In 24.1 [Iterator requirements] paragraph 5, it is stated ". . .
: Dereferenceable and past-the-end values are always non-singular."
:
: This places an unnecessary restriction on past-the-end iterators for
: containers with forward iterators (for example, a singly-linked list). If
: the past-the-end value on such a container was a well-known singular value,
: it would still satisfy all forward iterator requirements.
:
: Removing this restriction would allow, for example, a singly-linked list
: without a "footer" node.
I don't read the standard that way. The example is
int* p; // singular because it has no known value
however
int* q(0); // the nul pointer is not singular
The only operation allowed on a singular pointer/iterator is assignment
to. It may not be compared.
istream_iterator<char> it; // Not singular
It is a universal end iterator for all istream_iterator<char> regardless
of the stream.
Forward_iterator requires a default constructor which _might_ produce
a singular value. It might also not produce a singular value. That
does not mean that the end iterator for slist<T> is not allowed to
contain a nul pointer which gives it a non-singular value. AFAIK,
the SGI slist iterator meets all requirements for forward_iterator
and uses a nul pointer within the end iterator.
: This would have an impact on existing code that expects past-the-end
: iterators obtained from different (generic) containers being not equal.
That code is already broken. The standard does not say that the past
the end iterator is unique for each container.
John
---
[ 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: James Kuyper <kuyper@wizard.net>
Date: 2000/02/05 Raw View
scleary@jerviswebb.com wrote:
>
> [Moderator's note: forwarded to C++ Committee. -sdc ]
>
> Unnecessary restriction on past-the-end iterators
>
> Section: 24.1 [Iterator requirements]
> Submitter: Stephen Cleary
> Date: 02 February 2000
>
> In 24.1 [Iterator requirements] paragraph 5, it is stated ". . .
> Dereferenceable and past-the-end values are always non-singular."
>
> This places an unnecessary restriction on past-the-end iterators for
> containers with forward iterators (for example, a singly-linked list). If
> the past-the-end value on such a container was a well-known singular value,
> it would still satisfy all forward iterator requirements.
Not really. The only operation that is defined for singular iterator
values is their replacement by non-singular values (see 24.1 p6). In
particular, comparing a singular iterator to another iterator allows
undefined behavior. It's certainly not safe to copy them or assign them.
It would be rather embarrasing to define a container where any operation
user code performed on container.end() necessarily allowed undefined
behavior.
The canonical example of a singular value is not (T*)NULL. That's a
non-singular iterator that happens to also not be dereferencable. The
canonical singular iterator is an unitialized pointer. There are real
machines where loading an address value into an address register causes
that value to be validated. On those machines, loading an uninitialized
pointer can causes immediate termination of your program. This is a
deliberate safety measure: any program which would attempt to use an
uninitialized pointer is (IMO correctly) assumed to be so poorly written
that it can't be safely allowed to run.
---
[ 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: scleary@jerviswebb.com
Date: 2000/02/03 Raw View
[Moderator's note: forwarded to C++ Committee. -sdc ]
Unnecessary restriction on past-the-end iterators
Section: 24.1 [Iterator requirements]
Submitter: Stephen Cleary
Date: 02 February 2000
In 24.1 [Iterator requirements] paragraph 5, it is stated ". . .
Dereferenceable and past-the-end values are always non-singular."
This places an unnecessary restriction on past-the-end iterators for
containers with forward iterators (for example, a singly-linked list). If
the past-the-end value on such a container was a well-known singular value,
it would still satisfy all forward iterator requirements.
Removing this restriction would allow, for example, a singly-linked list
without a "footer" node.
This would have an impact on existing code that expects past-the-end
iterators obtained from different (generic) containers being not equal.
Proposed Resolution:
Change the wording of 24.1 [Iterator requirements] paragraph 5 to ". . .
Dereferenceable values are always non-singular. If the iterator category is
bidirectional or random access, a past-the-end value of that iterator is
always non-singular."
-Steve
[ 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 ]