rippled
Loading...
Searching...
No Matches
aged_container_iterator.h
1#pragma once
2
3#include <iterator>
4#include <type_traits>
5
6namespace beast {
7
8template <bool, bool, class, class, class, class, class>
10
11namespace detail {
12
13// If Iterator is SCARY then this iterator will be as well.
14template <bool is_const, class Iterator>
16{
17public:
19 using value_type = typename std::conditional<
20 is_const,
21 typename Iterator::value_type::stashed::value_type const,
22 typename Iterator::value_type::stashed::value_type>::type;
26 using time_point = typename Iterator::value_type::stashed::time_point;
27
29
30 // Disable constructing a const_iterator from a non-const_iterator.
31 // Converting between reverse and non-reverse iterators should be explicit.
32 template <
33 bool other_is_const,
34 class OtherIterator,
35 class = typename std::enable_if<
36 (other_is_const == false || is_const == true) &&
43
44 // Disable constructing a const_iterator from a non-const_iterator.
45 template <
46 bool other_is_const,
52
53 // Disable assigning a const_iterator to a non-const iterator
54 template <bool other_is_const, class OtherIterator>
55 auto
57 enable_if<other_is_const == false || is_const == true, aged_container_iterator&>::type
58 {
59 m_iter = other.m_iter;
60 return *this;
61 }
62
63 template <bool other_is_const, class OtherIterator>
64 bool
66 {
67 return m_iter == other.m_iter;
68 }
69
70 template <bool other_is_const, class OtherIterator>
71 bool
73 {
74 return m_iter != other.m_iter;
75 }
76
79 {
80 ++m_iter;
81 return *this;
82 }
83
86 {
87 aged_container_iterator const prev(*this);
88 ++m_iter;
89 return prev;
90 }
91
94 {
95 --m_iter;
96 return *this;
97 }
98
101 {
102 aged_container_iterator const prev(*this);
103 --m_iter;
104 return prev;
105 }
106
108 operator*() const
109 {
110 return m_iter->value;
111 }
112
113 pointer
115 {
116 return &m_iter->value;
117 }
118
119 time_point const&
120 when() const
121 {
122 return m_iter->when;
123 }
124
125private:
126 template <bool, bool, class, class, class, class, class>
128
129 template <bool, bool, class, class, class, class, class, class>
131
132 template <bool, class>
134
135 template <class OtherIterator>
136 aged_container_iterator(OtherIterator const& iter) : m_iter(iter)
137 {
138 }
139
140 Iterator const&
141 iterator() const
142 {
143 return m_iter;
144 }
145
146 Iterator m_iter;
147};
148
149} // namespace detail
150
151} // namespace beast
typename std::iterator_traits< Iterator >::iterator_category iterator_category
typename std::iterator_traits< Iterator >::difference_type difference_type
bool operator!=(aged_container_iterator< other_is_const, OtherIterator > const &other) const
bool operator==(aged_container_iterator< other_is_const, OtherIterator > const &other) const
typename Iterator::value_type::stashed::time_point time_point
typename std::conditional< is_const, typename Iterator::value_type::stashed::value_type const, typename Iterator::value_type::stashed::value_type >::type value_type
aged_container_iterator(aged_container_iterator< other_is_const, OtherIterator > const &other)
aged_container_iterator(aged_container_iterator< other_is_const, Iterator > const &other)
auto operator=(aged_container_iterator< other_is_const, OtherIterator > const &other) -> typename std::enable_if< other_is_const==false||is_const==true, aged_container_iterator & >::type
Associative container where each element is also indexed by time.
Associative container where each element is also indexed by time.