xrpld
Loading...
Searching...
No Matches
aged_container_iterator.h
1#pragma once
2
3#include <iterator>
4#include <type_traits>
5#include <utility>
6
7namespace beast {
8
9template <bool, bool, class, class, class, class, class>
11
12namespace detail {
13
14// If Iterator is SCARY then this iterator will be as well.
15template <bool IsConst, class Iterator>
17{
18public:
21 IsConst,
22 typename Iterator::value_type::Stashed::value_type const,
23 typename Iterator::value_type::Stashed::value_type>;
27 using time_point = Iterator::value_type::Stashed::time_point;
28
30
31 // Disable constructing a const_iterator from a non-const_iterator.
32 // Converting between reverse and non-reverse iterators should be explicit.
33 template <
34 bool OtherIsConst,
35 class OtherIterator,
36 class = std::enable_if_t<
37 (!OtherIsConst || IsConst) &&
38 !static_cast<bool>(std::is_same_v<Iterator, OtherIterator>)>>
43
44 // Disable constructing a const_iterator from a non-const_iterator.
45 template <bool OtherIsConst, class = std::enable_if_t<!OtherIsConst || IsConst>>
50
51 // Disable assigning a const_iterator to a non-const iterator
52 template <bool OtherIsConst, class OtherIterator>
53 auto
60
61 template <bool OtherIsConst, class OtherIterator>
62 bool
64 {
65 return iter_ == other.iter_;
66 }
67
68 template <bool OtherIsConst, class OtherIterator>
69 bool
71 {
72 return iter_ != other.iter_;
73 }
74
77 {
78 ++iter_;
79 return *this;
80 }
81
84 {
85 AgedContainerIterator const prev(*this);
86 ++iter_;
87 return prev;
88 }
89
92 {
93 --iter_;
94 return *this;
95 }
96
99 {
100 AgedContainerIterator const prev(*this);
101 --iter_;
102 return prev;
103 }
104
106 operator*() const
107 {
108 return iter_->value;
109 }
110
111 pointer
113 {
114 return &iter_->value;
115 }
116
117 [[nodiscard]] time_point const&
118 when() const
119 {
120 return iter_->when;
121 }
122
123private:
124 template <bool, bool, class, class, class, class, class>
126
127 template <bool, bool, class, class, class, class, class, class>
129
130 template <bool, class>
132
133 template <class OtherIterator>
134 AgedContainerIterator(OtherIterator iter) : iter_(std::move(iter))
135 {
136 }
137
138 [[nodiscard]] Iterator const&
139 iterator() const
140 {
141 return iter_;
142 }
143
144 Iterator iter_;
145};
146
147} // namespace detail
148
149} // namespace beast
AgedContainerIterator(AgedContainerIterator< OtherIsConst, Iterator > const &other)
bool operator!=(AgedContainerIterator< OtherIsConst, OtherIterator > const &other) const
std::iterator_traits< Iterator >::iterator_category iterator_category
AgedContainerIterator(AgedContainerIterator< OtherIsConst, OtherIterator > const &other)
auto operator=(AgedContainerIterator< OtherIsConst, OtherIterator > const &other) -> std::enable_if_t<!OtherIsConst||IsConst, AgedContainerIterator & >
std::conditional_t< IsConst, typename Iterator::value_type::Stashed::value_type const, typename Iterator::value_type::Stashed::value_type > value_type
std::iterator_traits< Iterator >::difference_type difference_type
Iterator::value_type::Stashed::time_point time_point
bool operator==(AgedContainerIterator< OtherIsConst, OtherIterator > const &other) const
T is_same_v
STL namespace.