Boost logo

Boost :

Subject: Re: [boost] difference_type size()?
From: Olaf van der Spek (ml_at_[hidden])
Date: 2011-10-19 10:44:25


On Wed, Oct 19, 2011 at 4:22 PM, Jeffrey Lee Hellrung, Jr.
<jeffrey.hellrung_at_[hidden]> 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.

Olaf


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk