1// (C) Copyright David Abrahams 2002.
2// (C) Copyright Jeremy Siek 2002.
3// (C) Copyright Thomas Witt 2002.
4// Distributed under the Boost Software License, Version 1.0. (See
5// accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7#ifndef BOOST_REVERSE_ITERATOR_23022003THW_HPP
8#define BOOST_REVERSE_ITERATOR_23022003THW_HPP
9
10#include <boost/iterator/iterator_adaptor.hpp>
11
12namespace boost {
13namespace iterators {
14
15 //
16 //
17 //
18 template <class Iterator>
19 class reverse_iterator
20 : public iterator_adaptor< reverse_iterator<Iterator>, Iterator >
21 {
22 typedef iterator_adaptor< reverse_iterator<Iterator>, Iterator > super_t;
23
24 friend class iterator_core_access;
25
26 public:
27 reverse_iterator() {}
28
29 explicit reverse_iterator(Iterator x)
30 : super_t(x) {}
31
32 template<class OtherIterator>
33 reverse_iterator(
34 reverse_iterator<OtherIterator> const& r
35 , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
36 )
37 : super_t(r.base())
38 {}
39
40 private:
41 typename super_t::reference dereference() const
42 {
43 Iterator it = this->base_reference();
44 --it;
45 return *it;
46 }
47
48 void increment() { --this->base_reference(); }
49 void decrement() { ++this->base_reference(); }
50
51 void advance(typename super_t::difference_type n)
52 {
53 this->base_reference() -= n;
54 }
55
56 template <class OtherIterator>
57 typename super_t::difference_type
58 distance_to(reverse_iterator<OtherIterator> const& y) const
59 {
60 return this->base_reference() - y.base();
61 }
62 };
63
64 template <class BidirectionalIterator>
65 inline reverse_iterator<BidirectionalIterator> make_reverse_iterator(BidirectionalIterator x)
66 {
67 return reverse_iterator<BidirectionalIterator>(x);
68 }
69
70} // namespace iterators
71
72using iterators::reverse_iterator;
73using iterators::make_reverse_iterator;
74
75} // namespace boost
76
77#endif // BOOST_REVERSE_ITERATOR_23022003THW_HPP
78