DGtal 1.3.0
Loading...
Searching...
No Matches
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/iterator/iterator_adaptor.hpp>
50
51namespace 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)
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.