[RFC] std::string(0);

Jonathan Wakely cow@compsoc.man.ac.uk
Mon Jun 14 08:20:00 GMT 2004


On Sat, Jun 12, 2004 at 09:13:48AM +0530, Dhruv Matani wrote:

> Actually, when I started learning about the STL about a year ago, I read
> in TC++PL, that end() for a container stood for *one past the last*
> valid iterator in a container.

Technically, end() is valid, but it is not dereferenceable
(a "valid" iterator is defined as one that is dereferenceable *or*
past-the-end)

So a better definition would be "one past the last dereferenceable
iterator" 

>                                So, when I applied it to an empty
> container, I was horribly confused!. This meant that an empty container
> and a container with only one element should have the same internal
> representation!, because end() was one *past* the last, so end() should
> be reachable from begin() after incrementing begin() at least once.

Your reasoning assumes that begin() for an empty container is a
dereferenceable iterator - but it isn't, it's past-the-end, and so
[begin,end()) is an empty range.

There's no double definition is you think in terms of dereferenceable
and past-the-end, and remember that "valid" includes past-the-end.

jon


-- 
"Subvert the dominant paradigm!"
	- The I.O.D.



More information about the Libstdc++ mailing list