1 #ifndef _theplu_yat_utility_container2d_iterator_
2 #define _theplu_yat_utility_container2d_iterator_
26 #include "concept_check.h"
27 #include "iterator_traits.h"
28 #include "yat_assert.h"
30 #include <boost/concept_check.hpp>
31 #include <boost/iterator/iterator_facade.hpp>
60 template<
typename Container,
typename value,
typename reference = value&>
62 :
public boost::iterator_facade<
63 Container2DIterator<Container, value, reference>
65 , boost::random_access_traversal_tag
88 : container_(&container), index_(row*container.columns()+column)
94 friend class boost::iterator_core_access;
96 Container* container_;
99 void advance(
int n) { index_+=n; }
101 void decrement(
void) { --index_; }
104 {
return other.index_ - index_; }
106 reference dereference(
void)
const
108 yat_assert<std::out_of_range>(index_ < this->size(),
109 "Container2DIterator::dereference");
110 return container_->operator()(row(index_), column(index_));
114 {
return index_ == other.index_; }
116 void increment(
void) { ++index_; }
118 size_t column(
size_t i)
const
119 {
return i % container_->columns(); }
120 size_t row(
size_t i)
const
121 {
return static_cast<size_t>(i/container_->columns()); }
123 {
return container_->columns()*container_->rows(); }
Concept check for Container2D.
Definition: concept_check.h:59
Iterator for a Container2D.
Definition: Container2DIterator.h:61
Container2DIterator(Container &container, size_t row, size_t column)
Constructor.
Definition: Container2DIterator.h:87
Container2DIterator(void)
Default Constructor.
Definition: Container2DIterator.h:75