Changeset 1490 for trunk/yat/utility


Ignore:
Timestamp:
Sep 12, 2008, 12:10:26 AM (13 years ago)
Author:
Peter
Message:

fixes #440

The bug was introduced in trunk after 0.4 release, so it has never
seen daylight.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/StrideIterator.h

    r1487 r1490  
    2323  along with yat. If not, see <http://www.gnu.org/licenses/>.
    2424*/
     25
     26// debug
     27#include <iostream>
    2528
    2629#include "iterator_traits.h"
     
    8891    : public boost::iterator_adaptor<StrideIterator<Iter>, Iter>
    8992  {
     93    typedef boost::iterator_adaptor<StrideIterator<Iter>,Iter> super_t;
     94
    9095  public:
    9196    /// type of underlying iterator
    9297    typedef Iter iterator_type;
     98
     99    /*
    93100    /// value type
    94101    typedef typename std::iterator_traits<Iter>::value_type value_type;
     
    101108    /// weighted_iterator_tag if iterator is weighted
    102109    typedef typename yat::utility::weighted_iterator_traits<Iter>::type w_type;
     110    */
    103111
    104112    /**
     
    107115       Using default constructor of BASE iterator.
    108116     */
    109     StrideIterator(size_t stride=1)
     117    explicit StrideIterator(size_t stride=1)
    110118      : StrideIterator::iterator_adaptor_(), stride_(stride) {}
    111119
     
    117125
    118126   
     127    /**
     128       \brief Copy constructor
     129     */
     130    StrideIterator(const StrideIterator& other)
     131      : StrideIterator::iterator_adaptor_(other.base()), stride_(other.stride())
     132    {}
     133
    119134    /**
    120135       \brief Conversion constructor.
     
    130145        stride_(other.stride()) {}
    131146
     147    /**
     148        \brief Assignment operator
     149     */
     150    StrideIterator& operator=(const StrideIterator& rhs)
     151    {
     152      stride_ = rhs.stride();
     153      this->base_reference() = rhs.base();
     154      return *this;
     155    }
     156
    132157    /**
    133158       \return stride
     
    141166    size_t stride_;
    142167
     168    //typedef typename StrideIterator::iterator_adaptor_::difference_type
    143169    typedef typename StrideIterator::iterator_adaptor_::difference_type
    144170    difference_t;
    145171
    146     void advance(difference_t n){ this->base_reference() += stride_*n; }
     172    void advance(typename super_t::difference_type n)
     173    { this->base_reference() += stride_*n; }
     174
    147175    void decrement(void) { this->base_reference()-=stride_; }
    148176
    149177    template <class OtherIterator>
    150     difference_t distance_type(const StrideIterator<OtherIterator>& other) const
    151     { return (other.base() - this->base())/stride_; }
     178    typename super_t::difference_type
     179    distance_to(const StrideIterator<OtherIterator>& other) const
     180    {
     181      // casting to int to avoid loss of sign in numerator
     182      return (other.base() - this->base() )/static_cast<int>(stride_);
     183    }
    152184
    153185    void increment(void) { this->base_reference()+=stride_; }
    154186
    155     // Using compiler generated copy
    156     //StrideIterator(const StrideIterator&);
    157     //StrideIterator& operator=(const StrideIterator&);
    158187  };
    159188
Note: See TracChangeset for help on using the changeset viewer.