Topic: DR: LWG #280, null values, singular values and past-the-end iterators
Author: =?ISO-8859-1?Q?Joaqu=EDn_M_L=F3pez_Mu=F1oz?= <joaquin@tid.es>
Date: Wed, 27 May 2009 10:38:20 CST Raw View
Hi,
I'm following here the text of C++0x as it appears in the latest draft
(N2857).
Null pointer values (4.10/1) mostly behave as regular pointer values
(they can be copied around and tested for equality, for instance),
except that they cannot be dereferenced. On a distant section of
the standard, iterator concepts, 24.2/6 states that iterators can
take so-called singular values (as an example of such value it
proposes an uninitialized pointer). Iterators holding a singular value
can only be destroyed or assigned a non-singular value; all other
operations engender undefined behavior. Now, I'd like to quote
two statements in 24.2/6
(1) The library never assumes that past-the-end values are
dereferenceable.
(2) Dereferenceable values are always non-singular.
Lacking any other provision in the standard, the consequence of
(1) and (2) is that past-the-end iterators cannot be assumed
to be non-singular. In particular, one cannot legally assume
that past-the-end iterators are copyable, which of course renders
the std library unusable:
iterator first=c.begin(),last=c.end();
std::sort(first,last); // illegal, last not guranteed to be copyable
Statement (2) was changed in TC1; whereas C++98 read:
(2 C++98) Dereferenceable and past-the-end values are always
non-singular.
This change is the result of LWG issue #280
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#208
where part of the rationale is to allow null pointers to serve as
past-the-end iterators; the issue rationale explicitly states that
"null pointers are singular". The problem with this is that
null pointers are not singular (in the sense that they support
many more operations than singular values can be assumed
to suport), they are merely non-dereferenceable. Treating them
as singular render them useless for acting as past-the-end
iterators.
Joaqu n M L pez Mu oz
Telef nica, Investigaci n y Desarrollo
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]