Boost logo

Boost :

From: Neal D. Becker (ndbecker2_at_[hidden])
Date: 2004-04-12 13:32:35

According to

template <class Dr1, class V1, class TC1, class R1, class D1,
          class Dr2, class V2, class TC2, class R2, class D2>
typename enable_if_interoperable<Dr1,Dr2,difference>::type
operator -(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);

Return Type:

if is_convertible<Dr2,Dr1>::value

difference shall be iterator_traits<Dr1>::difference_type.
difference shall be iterator_traits<Dr2>::difference_type


if is_convertible<Dr2,Dr1>::value

-((Dr1 const&)lhs).distance_to((Dr2 const&)rhs).
((Dr2 const&)rhs).distance_to((Dr1 const&)lhs).

Is the preference for the former case over the latter intentional? 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,
      typedef typename iterator_traits<_RandomAccessIter>::difference_type
      for (_Distance __n = __last - __first; __n > 0; --__n) {
        *__result = *__first;
      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,
but the way iterator_adaptors is implemented, it wants a negative distance.
Not hard to workaround, but it seemed odd that the default case was
inverted, and I wondered if that was really intentional.

Boost list run by bdawes at, gregod at, cpdaniel at, john at