#ifndef REGH #define REGH #include #include #include using namespace std; class sudoku; class box; class reg { static const size_t root = 3; static const size_t n = root * root; sudoku *p; size_t x; size_t y; public: friend class sudoku; class iterator: public std::iterator { sudoku *const p; size_t x; size_t y; public: iterator(sudoku *initial_p, size_t initial_x, size_t initial_y): p(initial_p), x(initial_x), y(initial_y) {} box& operator*() const; box *operator->() const {return &**this;} iterator& operator++() { const size_t remainder = x % root; if (remainder < root - 1) { ++x; } else { x -= remainder; ++y; } return *this; } friend bool operator==(const iterator& it1, const iterator& it2) { return it1.p == it2.p && it1.x == it2.x && it1.y == it2.y; } }; iterator begin() const {return iterator(p, x * root, y * root);} iterator end() const {return iterator(p, x * root, y * root + root);} }; inline bool operator!=(const reg::iterator& it1, const reg::iterator& it2) { return !(it1 == it2); } #endif