On 9 April 2014 23:32, David Hunter <
davidh...@gmail.com> wrote:
> + size()) must be a valid range. Note that "valid range" does not seems to
> be defined anywhere in the standard. So is it reasonable for instance for
[iterator.requirements.general]/7:
"Most of the library's algorithmic templates that operate on data
structures have interfaces that use ranges.
A range is a pair of iterators that designate the beginning and end of
the computation. A range [i,i) is an
empty range; in general, a range [i,j) refers to the elements in the
data structure starting with the element
pointed to by i and up to but not including the element pointed to by
j. Range [i,j) is valid if and only if
j is reachable from i. The result of the application of functions in
the library to invalid ranges is undefined."
The reachability is in the previous paragraph (6):
"An iterator j is called reachable from an iterator i if and only if
there is a finite sequence of applications of
the expression ++i that makes i == j. If j is reachable from i, they
refer to elements of the same sequence."
> data() to return a nullptr, in other words is [nullptr, nullptr + 0) a valid
> range? If it isn't should the implementation return some random pointer? Is
> the implementation free to choose whether to return a nullptr or a random
> pointer?
Based on those paragraphs, yes, that is a valid range, an implementation
does not need to return a random pointer, but yes, it can do so. It can return
the address of the container itself, for instance.