Re: difference_type size()?
<andrey.semashev <at> gmail.com>
2011-10-19 18:53:38 GMT
On Wednesday, October 19, 2011 16:44:25 Olaf van der Spek wrote:
> On Wed, Oct 19, 2011 at 4:22 PM, Jeffrey Lee Hellrung, Jr.
>
> <jeffrey.hellrung <at> gmail.com> wrote:
> >> Sounds like a very weak reason. Especially since:
> >> If an instance of iterator_range is constructed by a client with two
> >> iterators, the client must ensure that the two iterators delimit a
> >> valid closed-open range [begin,end).
> >>
> >> If that's the rationale, it'd be better to add is_valid() or so.
> >
> > What are the requirements on an iterator's difference_type, exactly?
>
> I don't know.
>
> > Specifically, are you even guaranteed that it is always convertible to
> > *some* unsigned integral type, much less specifically std::size_t? And,
> > if so, how would you deduce such an unsigned integral type?
>
> Good questions. But I don't think I know the answer.
> However, given a valid range, end() - begin() can't be negative. Right?
> Most other size() return an unsigned type. Returning a signed type
> results in signed/unsigned mismatches.
There are some points in the Standard, like this for instance (24.2.1/1):
... For every iterator type X for which equality is defined, there is a
corresponding signed integer type called the difference type of the iterator.
However, that's not really relevant, because there is no requirement that
(Continue reading)