Boost logo

Boost :

Subject: Re: [boost] difference_type size()?
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-10-19 10:22:00


On Wed, Oct 19, 2011 at 1:46 AM, Olaf van der Spek <ml_at_[hidden]> wrote:

> On Wed, Oct 19, 2011 at 1:45 AM, Rhys Ulerich <rhys.ulerich_at_[hidden]>
> wrote:
> >> iterator_range returns a signed size. Is this correct?
> >> IMO it should return size_t.
> >>
> >> boost\range\iterator_range_core.hpp:
> >> difference_type size() const
> >> {
> >> return m_End - m_Begin;
> >> }
> >
> > Random thought: It seems like advance_begin and advance_end could be
> > used to create a strictly negative size. Returning difference_type
> > allows this to be detected while a size_type does not.
>
> 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?
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?

- Jeff


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