rippled
Loading...
Searching...
No Matches
aged_container_iterator.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef BEAST_CONTAINER_DETAIL_AGED_CONTAINER_ITERATOR_H_INCLUDED
21#define BEAST_CONTAINER_DETAIL_AGED_CONTAINER_ITERATOR_H_INCLUDED
22
23#include <iterator>
24#include <type_traits>
25
26namespace beast {
27
28template <bool, bool, class, class, class, class, class>
30
31namespace detail {
32
33// If Iterator is SCARY then this iterator will be as well.
34template <bool is_const, class Iterator>
36{
37public:
40 using value_type = typename std::conditional<
41 is_const,
42 typename Iterator::value_type::stashed::value_type const,
43 typename Iterator::value_type::stashed::value_type>::type;
48 using time_point = typename Iterator::value_type::stashed::time_point;
49
51
52 // Disable constructing a const_iterator from a non-const_iterator.
53 // Converting between reverse and non-reverse iterators should be explicit.
54 template <
55 bool other_is_const,
56 class OtherIterator,
57 class = typename std::enable_if<
58 (other_is_const == false || is_const == true) &&
65
66 // Disable constructing a const_iterator from a non-const_iterator.
67 template <
68 bool other_is_const,
69 class = typename std::enable_if<
70 other_is_const == false || is_const == true>::type>
76
77 // Disable assigning a const_iterator to a non-const iterator
78 template <bool other_is_const, class OtherIterator>
79 auto
82 typename std::enable_if<
83 other_is_const == false || is_const == true,
85 {
86 m_iter = other.m_iter;
87 return *this;
88 }
89
90 template <bool other_is_const, class OtherIterator>
91 bool
93 other) const
94 {
95 return m_iter == other.m_iter;
96 }
97
98 template <bool other_is_const, class OtherIterator>
99 bool
101 other) const
102 {
103 return m_iter != other.m_iter;
104 }
105
108 {
109 ++m_iter;
110 return *this;
111 }
112
115 {
116 aged_container_iterator const prev(*this);
117 ++m_iter;
118 return prev;
119 }
120
123 {
124 --m_iter;
125 return *this;
126 }
127
130 {
131 aged_container_iterator const prev(*this);
132 --m_iter;
133 return prev;
134 }
135
137 operator*() const
138 {
139 return m_iter->value;
140 }
141
142 pointer
144 {
145 return &m_iter->value;
146 }
147
148 time_point const&
149 when() const
150 {
151 return m_iter->when;
152 }
153
154private:
155 template <bool, bool, class, class, class, class, class>
157
158 template <bool, bool, class, class, class, class, class, class>
160
161 template <bool, class>
163
164 template <class OtherIterator>
165 aged_container_iterator(OtherIterator const& iter) : m_iter(iter)
166 {
167 }
168
169 Iterator const&
170 iterator() const
171 {
172 return m_iter;
173 }
174
175 Iterator m_iter;
176};
177
178} // namespace detail
179
180} // namespace beast
181
182#endif
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.