Boost logo

Boost :

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


On Wed, Oct 19, 2011 at 11:38 AM, <andrey.semashev_at_[hidden]> wrote:

> On Tuesday, October 18, 2011 23:30:03 Olaf van der Spek wrote:
> > Hi,
> >
> > iterator_range returns a signed size. Is this correct?
> > IMO it should return size_t.
>
> +1
>
> I too stumbled upon this more than once. The common understanding of a
> valid
> range is that end() must be reachable by incrementing begin() finite times.
> Making the size signed makes little sense to me and it also introduces a
> problem (rather theoretical, however) when iterator_range is constructed
> from
> a very large valid range, whose size exceeds
> numeric_limits<difference_type>::max().
>

How would that be possible? Doesn't that violate the conditions on
difference_type that it is able to represent the (signed) distance between
any two iterators within the same range?

Also, assuming that size() should return an unsigned integer type (I'm not
debating the merits of this), *what* unsigned integer type should that be?
I don't know of any general way to go from difference_type to a "compatible"
unsigned integer type. I suspect this will end up being filed away as "nice
to have but ultimately unimplementable generically" given current range
interfaces.

- Jeff


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