Boost logo

Boost :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2007-11-14 07:23:59


JOAQUIN LOPEZ MU?Z skrev:
>
> ----- Mensaje original -----
> De: David Abrahams <dave_at_[hidden]>
> Fecha: Viernes, Noviembre 9, 2007 4:23 pm
> Asunto: Re: [boost] [range] range_size<T> deprecation, updated docs
> etc.
> Para: boost_at_[hidden]
>
>> on Fri Nov 09 2007, Thorsten Ottosen <nesotto-AT-cs.aau.dk> wrote:
> [...]
>>> "template<class InputIterator>
>>> typename iterator_traits<InputIterator>::difference_type
>>> distance(InputIterator first, InputIterator last);
>>> 4 Effects: Returns the number of increments or decrements needed
>> to get
>>> from first to last.
>>> 5 Requires: last shall be reachable from first."
>>>
>>> How can one ever use decrements to get from first to last?
>> When InputIterator is a random access iterator, last < first does not
>> violate the precondition.
>
> I'm afraid (last<first) violates the precondition even with
> random access iterators, according to 24.1.6 and as explicitly
> acknowledged at
> http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#204 .
> This is IMHO an unfortunate decision by the committee and renders
> the "or decrements" bit in the effects clause of std::distance
> void and misleading.

Thanks for the link.

I'm convinced that boost::size(Rng&) can assert the result to be
positive and similar for boost::distance(Rng&). The Range concept
requires "forward" reachability; otherwise [x,y) makes no sense.

-Thorsten


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