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::detail {
8
9// If Iterator is SCARY then this iterator will be as well.
10template <bool IsConst, class Iterator>
12{
13public:
16 IsConst,
17 typename Iterator::value_type::Stashed::value_type const,
18 typename Iterator::value_type::Stashed::value_type>;
22 using time_point = Iterator::value_type::Stashed::time_point;
23
25
26 // Disable constructing a const_iterator from a non-const_iterator.
27 // Converting between reverse and non-reverse iterators should be explicit.
28 template <bool OtherIsConst, class OtherIterator>
30 requires(
31 (!OtherIsConst || IsConst) &&
33 : iter_(other.iter_)
34 {
35 }
36
37 // Disable constructing a const_iterator from a non-const_iterator.
38 template <bool OtherIsConst>
40 requires(!OtherIsConst || IsConst)
41 : iter_(other.iter_)
42 {
43 }
44
45 // Disable assigning a const_iterator to a non-const iterator
46 template <bool OtherIsConst, class OtherIterator>
47 auto
50 requires(!OtherIsConst || IsConst)
51 {
52 iter_ = other.iter_;
53 return *this;
54 }
55
56 template <bool OtherIsConst, class OtherIterator>
57 bool
59 {
60 return iter_ == other.iter_;
61 }
62
63 template <bool OtherIsConst, class OtherIterator>
64 bool
66 {
67 return iter_ != other.iter_;
68 }
69
72 {
73 ++iter_;
74 return *this;
75 }
76
79 {
80 AgedContainerIterator const prev(*this);
81 ++iter_;
82 return prev;
83 }
84
87 {
88 --iter_;
89 return *this;
90 }
91
94 {
95 AgedContainerIterator const prev(*this);
96 --iter_;
97 return prev;
98 }
99
101 operator*() const
102 {
103 return iter_->value;
104 }
105
106 pointer
108 {
109 return &iter_->value;
110 }
111
112 [[nodiscard]] time_point const&
113 when() const
114 {
115 return iter_->when;
116 }
117
118private:
119 template <bool, bool, class, class, class, class, class>
121
122 template <bool, bool, class, class, class, class, class, class>
124
125 template <bool, class>
127
128 template <class OtherIterator>
129 AgedContainerIterator(OtherIterator iter) : iter_(std::move(iter))
130 {
131 }
132
133 [[nodiscard]] Iterator const&
134 iterator() const
135 {
136 return iter_;
137 }
138
139 Iterator iter_;
140};
141
142} // namespace beast::detail
AgedContainerIterator(AgedContainerIterator< OtherIsConst, Iterator > const &other)
bool operator!=(AgedContainerIterator< OtherIsConst, OtherIterator > const &other) const
auto operator=(AgedContainerIterator< OtherIsConst, OtherIterator > const &other) -> AgedContainerIterator &requires(!OtherIsConst||IsConst)
std::iterator_traits< Iterator >::iterator_category iterator_category
AgedContainerIterator(AgedContainerIterator< OtherIsConst, OtherIterator > const &other)
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.