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 , std::random_access_iterator_tag
78 BOOST_CONCEPT_ASSERT((boost::Convertible<reference,value>));
89 : container_(&container), index_(row*container.columns()+column)
92 BOOST_CONCEPT_ASSERT((boost::Convertible<reference,value>));
96 friend class boost::iterator_core_access;
98 Container* container_;
101 void advance(
int n) { index_+=n; }
103 void decrement(
void) { --index_; }
106 {
return other.index_ - index_; }
108 reference dereference(
void)
const
110 yat_assert<std::out_of_range>(index_ < this->size(),
111 "Container2DIterator::dereference");
112 return container_->operator()(row(index_), column(index_));
116 {
return index_ == other.index_; }
118 void increment(
void) { ++index_; }
120 size_t column(
size_t i)
const
121 {
return i % container_->columns(); }
122 size_t row(
size_t i)
const
123 {
return static_cast<size_t>(i/container_->columns()); }
125 {
return container_->columns()*container_->rows(); }