Ignore:
Timestamp:
Feb 11, 2008, 12:09:04 AM (14 years ago)
Author:
Peter
Message:

using std::iterator in Iterator

File:
1 edited

Legend:

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

    r1062 r1067  
    4141  template<typename Container, typename T>
    4242  class Iterator
     43    : public std::iterator<std::random_access_iterator_tag, double, size_t, T,
     44                           void>
    4345  {
    4446  public:
    45     typedef std::random_access_iterator_tag iterator_category;
    46     typedef double value_type;
    47     typedef size_t difference_type;
     47    //typedef size_t difference_type;
    4848    typedef T reference;
    4949    typedef double* pointer;
     
    6565       \param colun telling which column iterator points to
    6666    */
    67     Iterator(Container& container, difference_type row, difference_type column)
     67    Iterator(Container& container, size_t row, size_t column)
    6868      : container_(&container), index_(row*container.columns()+column) {}
    6969
     
    8181       \return element \a n steps forward
    8282     */
    83     reference operator[](difference_type n) const
     83    reference operator[](size_t n) const
    8484    {
    8585      yat_assert<std::out_of_range>(index_+n < this->size(),
     
    137137       \return copy of resulting iterator
    138138     */
    139     friend Iterator operator+(const Iterator& lhs, difference_type n)
     139    friend Iterator operator+(const Iterator& lhs, size_t n)
    140140    { return self(*lhs.container_, lhs.index_+n); }
    141141
     
    145145       \return copy of resulting iterator
    146146     */
    147     friend Iterator operator-(const Iterator& lhs, difference_type n)
     147    friend Iterator operator-(const Iterator& lhs, size_t n)
    148148    { return self(*lhs.container_, lhs.index_-n); }
    149149
     
    153153       \return distance between \a lhs and \a rhs
    154154     */
    155     friend difference_type operator-(const Iterator& lhs, const Iterator& rhs)
     155    friend size_t operator-(const Iterator& lhs, const Iterator& rhs)
    156156    {
    157157      yat_assert<std::runtime_error>(lhs.container_==rhs.container_,
     
    227227  private:
    228228    Container* container_;
    229     difference_type index_;
    230 
    231     difference_type column(difference_type i) const
     229    size_t index_;
     230
     231    size_t column(size_t i) const
    232232    { return i % container_->columns(); }
    233     difference_type row(difference_type i) const
    234     { return static_cast<difference_type>(i/container_->columns()); }
    235     difference_type size() const
     233    size_t row(size_t i) const
     234    { return static_cast<size_t>(i/container_->columns()); }
     235    size_t size() const
    236236    { return container_->columns()*container_->rows(); }
    237237
Note: See TracChangeset for help on using the changeset viewer.