
On Wed, Oct 19, 2011 at 12:21 PM, Olaf van der Spek <ml@vdspek.org> wrote:
On Wed, Oct 19, 2011 at 8:50 PM, Jeffrey Lee Hellrung, Jr. <jeffrey.hellrung@gmail.com> wrote:
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?
How about using make_unsigned from type_traits?
See my reply to Andrey. Note that I'm not confident that make_unsigned *wouldn't* work, necessarily.
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.
Isn't this problem caused by iterator_traits missing size_type?
Yes. Changing iterator_traits (specifically, the collection of types associated with an iterator) is where I'm leaning, if you really want an unsigned iterator_range::size().
What would the problem be of just using std::size_t?
Well, likewise, what would be the problem of always using std::ptrdiff_t for difference_type? And, aside from whether std::size_t would be wide enough, I don't think there are any requirements that std::size_t be constructable from difference_type. - Jeff