DGtal  1.5.beta
ReverseIterator.h
1 
17 #pragma once
18 
31 #if defined(ReverseIterator_RECURSES)
32 #error Recursive header files inclusion detected in ReverseIterator.h
33 #else // defined(ReverseIterator_RECURSES)
35 #define ReverseIterator_RECURSES
36 
37 #if !defined ReverseIterator_h
39 #define ReverseIterator_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/IteratorCirculatorTraits.h"
46 #include <boost/iterator.hpp>
47 #include <boost/utility.hpp>
48 #include <boost/next_prior.hpp>
49 #include <boost/iterator/iterator_adaptor.hpp>
51 
52 namespace DGtal
53 {
54 
56  // template class ReverseIterator
68  template <class Iterator>
70  : public boost::iterator_adaptor< ReverseIterator<Iterator>, Iterator >
71  {
72 
73  typedef boost::iterator_adaptor< ReverseIterator<Iterator>, Iterator > super_t;
74 
76 
77  public:
78 
80 
82 
83  explicit ReverseIterator(Iterator x)
84  : super_t(x) {}
85 
86  template<class OtherIterator>
89  , typename boost::enable_if_convertible<OtherIterator, Iterator>::type* = 0
90  )
91  : super_t(r.base())
92  {}
93 
94  private:
95  typename super_t::reference dereference() const { return *boost::prior(this->base()); }
96 
97  void increment() { --this->base_reference(); }
98  void decrement() { ++this->base_reference(); }
99 
100  void advance(typename super_t::difference_type n)
101  {
102  this->base_reference() += -n;
103  }
104 
105  template <class OtherIterator>
106  typename super_t::difference_type
108  {
109  return this->base_reference() - y.base();
110  }
111  };
112 
113 } // namespace DGtal
114 
115 
117 // Includes inline functions.
118 //#include "DGtal/base/ReverseIterator.ih"
119 
120 // //
122 
123 #endif // !defined ReverseIterator_h
124 
125 #undef ReverseIterator_RECURSES
126 #endif // else defined(ReverseIterator_RECURSES)
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa.
ReverseIterator(ReverseIterator< OtherIterator > const &r, typename boost::enable_if_convertible< OtherIterator, Iterator >::type *=0)
super_t::reference dereference() const
IteratorCirculatorTraits< Iterator >::Type Type
void advance(typename super_t::difference_type n)
friend class boost::iterator_core_access
boost::iterator_adaptor< ReverseIterator< Iterator >, Iterator > super_t
super_t::difference_type distance_to(ReverseIterator< OtherIterator > const &y) const
DGtal is the top-level namespace which contains all DGtal functions and types.