DGtal  0.9.2
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)
34 
35 #define ReverseIterator_RECURSES
36 
37 #if !defined ReverseIterator_h
38 
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/iterator/iterator_adaptor.hpp>
50 
51 namespace DGtal
52 {
53 
55  // template class ReverseIterator
67  template <class Iterator>
69  : public boost::iterator_adaptor< ReverseIterator<Iterator>, Iterator >
70  {
71 
72  typedef boost::iterator_adaptor< ReverseIterator<Iterator>, Iterator > super_t;
73 
75 
76  public:
77 
79 
81 
82  explicit ReverseIterator(Iterator x)
83  : super_t(x) {}
84 
85  template<class OtherIterator>
88  , typename boost::enable_if_convertible<OtherIterator, Iterator>::type* = 0
89  )
90  : super_t(r.base())
91  {}
92 
93  private:
94  typename super_t::reference dereference() const { return *boost::prior(this->base()); }
95 
96  void increment() { --this->base_reference(); }
97  void decrement() { ++this->base_reference(); }
98 
99  void advance(typename super_t::difference_type n)
100  {
101  this->base_reference() += -n;
102  }
103 
104  template <class OtherIterator>
105  typename super_t::difference_type
107  {
108  return this->base_reference() - y.base();
109  }
110  };
111 
112 } // namespace DGtal
113 
114 
116 // Includes inline functions.
117 //#include "DGtal/base/ReverseIterator.ih"
118 
119 // //
121 
122 #endif // !defined ReverseIterator_h
123 
124 #undef ReverseIterator_RECURSES
125 #endif // else defined(ReverseIterator_RECURSES)
void advance(typename super_t::difference_type n)
IteratorCirculatorTraits< Iterator >::Type Type
super_t::difference_type distance_to(ReverseIterator< OtherIterator > const &y) const
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa...
DGtal is the top-level namespace which contains all DGtal functions and types.
friend class boost::iterator_core_access
boost::iterator_adaptor< ReverseIterator< Iterator >, Iterator > super_t
ReverseIterator(ReverseIterator< OtherIterator > const &r, typename boost::enable_if_convertible< OtherIterator, Iterator >::type *=0)
super_t::reference dereference() const