|
Boost : |
From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2007-11-09 10:48:25
----- 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.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk