Boost logo

Boost Users :

From: Olaf Petzold (yg-boost-users_at_[hidden])
Date: 2003-04-11 07:53:13


Hello,

I try to write a cyclic Iterator using boost::iterator_adaptors.
Unfortunally, the advance function doesn't work for negative distances
correct:

template<class Iterator>
class cycle_iterator_policies
{
public:
  cycle_iterator_policies(const Iterator& begin, const Iterator& end)
    : m_begin( begin ), m_end( end )
    {
      assert( m_begin != m_end );
    }
 ....
  template<class IteratorAdaptor, class DifferenceType>
  void advance( IteratorAdaptor& x, DifferenceType n ) {
    n %= std::distance( m_begin, m_end );
    DifferenceType rest = std::distance( x.base(), m_end );
    if( n < rest )
      std::advance( x.base(), n );
    else
      std::advance( x.base() = m_begin, n - rest );
  }

  ....
private:
  Iterator m_begin;
  Iterator m_end;
};

It seems to be an algorithmic problem for me. How can I corrected it?

Thanks
Olaf


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net