Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-04-12 14:56:56


"Neal D. Becker" <ndbecker2_at_[hidden]> writes:

> Is the preference for the former case over the latter intentional?

Not particularly; it just worked out that way. I guess in the
interest of efficiency it'd be better to take the one that doesn't
involve a unary minus.

> This
> caused some surprise when I tried to re-implement my
> cycle_iterator_adapator (a kind of circular buffer adaptor).
>
> std::copy (b, a, ...)
> will do:
> template<typename _RandomAccessIter, typename _OutputIter>
> inline _OutputIter
> __copy(_RandomAccessIter __first, _RandomAccessIter __last,
> _OutputIter __result,
> random_access_iterator_tag)
> {
> typedef typename iterator_traits<_RandomAccessIter>::difference_type
> _Distance;
> for (_Distance __n = __last - __first; __n > 0; --__n) {
> *__result = *__first;
> ++__first;
> ++__result;
> }
> return __result;
> }
>
> As I implemented cycle_iterator_adaptor distance_to, it was expecting that
> given iterators [a,b], you probably want a positive distance from a
> to b,

Correct, if b is reachable by applying increments to a.

> but the way iterator_adaptors is implemented, it wants a negative
> distance.

Huh? What do you mean "it wants"?

> Not hard to workaround, but it seemed odd that the default case was
> inverted, and I wondered if that was really intentional.

Now I'm completely confused.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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