// -*- coding: utf-8 -*- // Time-stamp: #ifndef ITERATOR_H #define ITERATOR_H #include "array2d.hpp" template class Iterator { public: // Constructors Iterator(Array2d& a, int m, int n) : rep(a.rep), i(m), j(n) {} // Equality bool operator==(Iterator it) const; // Non-equality defined using equality bool operator!=(Iterator it) const { return !(*this == it); } // Incrementation Iterator& operator++(); // Dereference T& operator*() const; private: Rep* rep; // Link to the array int i; // Line index int j; // Column index }; template bool Iterator::operator==(Iterator it) const { return i == it.i && j == it.j; } // Incrementation template Iterator& Iterator::operator++() { if (i < rep->nlin && ++j == rep->ncol) { j = 0; ++i; } return *this; } // Dereference template T& Iterator::operator*() const { return (*rep)[i][j]; } #endif