rippled
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 
26 namespace beast {
27 
28 template <bool, bool, class, class, class, class, class>
30 
31 namespace detail {
32 
33 // Idea for Base template argument to prevent having to repeat
34 // the base class declaration comes from newbiz on ##c++/Freenode
35 //
36 // If Iterator is SCARY then this iterator will be as well.
37 template <
38  bool is_const,
39  class Iterator,
40  class Base = std::iterator<
42  typename std::conditional<
43  is_const,
44  typename Iterator::value_type::stashed::value_type const,
45  typename Iterator::value_type::stashed::value_type>::type,
47 class aged_container_iterator : public Base
48 {
49 public:
50  using time_point = typename Iterator::value_type::stashed::time_point;
51 
52  aged_container_iterator() = default;
53 
54  // Disable constructing a const_iterator from a non-const_iterator.
55  // Converting between reverse and non-reverse iterators should be explicit.
56  template <
57  bool other_is_const,
58  class OtherIterator,
59  class OtherBase,
60  class = typename std::enable_if<
61  (other_is_const == false || is_const == true) &&
65  other)
66  : m_iter(other.m_iter)
67  {
68  }
69 
70  // Disable constructing a const_iterator from a non-const_iterator.
71  template <
72  bool other_is_const,
73  class OtherBase,
74  class = typename std::enable_if<
75  other_is_const == false || is_const == true>::type>
78  other)
79  : m_iter(other.m_iter)
80  {
81  }
82 
83  // Disable assigning a const_iterator to a non-const iterator
84  template <bool other_is_const, class OtherIterator, class OtherBase>
85  auto
88  other) ->
89  typename std::enable_if<
90  other_is_const == false || is_const == true,
92  {
93  m_iter = other.m_iter;
94  return *this;
95  }
96 
97  template <bool other_is_const, class OtherIterator, class OtherBase>
98  bool
101  other) const
102  {
103  return m_iter == other.m_iter;
104  }
105 
106  template <bool other_is_const, class OtherIterator, class OtherBase>
107  bool
110  other) const
111  {
112  return m_iter != other.m_iter;
113  }
114 
117  {
118  ++m_iter;
119  return *this;
120  }
121 
124  {
125  aged_container_iterator const prev(*this);
126  ++m_iter;
127  return prev;
128  }
129 
132  {
133  --m_iter;
134  return *this;
135  }
136 
139  {
140  aged_container_iterator const prev(*this);
141  --m_iter;
142  return prev;
143  }
144 
145  typename Base::reference
146  operator*() const
147  {
148  return m_iter->value;
149  }
150 
151  typename Base::pointer
152  operator->() const
153  {
154  return &m_iter->value;
155  }
156 
157  time_point const&
158  when() const
159  {
160  return m_iter->when;
161  }
162 
163 private:
164  template <bool, bool, class, class, class, class, class>
166 
167  template <bool, bool, class, class, class, class, class, class>
169 
170  template <bool, class, class>
172 
173  template <class OtherIterator>
174  aged_container_iterator(OtherIterator const& iter) : m_iter(iter)
175  {
176  }
177 
178  Iterator const&
179  iterator() const
180  {
181  return m_iter;
182  }
183 
184  Iterator m_iter;
185 };
186 
187 } // namespace detail
188 
189 } // namespace beast
190 
191 #endif
beast::detail::aged_container_iterator::operator=
auto operator=(aged_container_iterator< other_is_const, OtherIterator, OtherBase > const &other) -> typename std::enable_if< other_is_const==false||is_const==true, aged_container_iterator & >::type
Definition: aged_container_iterator.h:86
std::is_same
beast::detail::aged_container_iterator::operator++
aged_container_iterator & operator++()
Definition: aged_container_iterator.h:116
beast::detail::aged_container_iterator::operator==
bool operator==(aged_container_iterator< other_is_const, OtherIterator, OtherBase > const &other) const
Definition: aged_container_iterator.h:99
beast::detail::aged_container_iterator::when
time_point const & when() const
Definition: aged_container_iterator.h:158
beast::detail::aged_container_iterator::m_iter
Iterator m_iter
Definition: aged_container_iterator.h:184
iterator
beast::detail::aged_container_iterator::aged_container_iterator
aged_container_iterator(aged_container_iterator< other_is_const, Iterator, OtherBase > const &other)
Definition: aged_container_iterator.h:76
beast::detail::aged_container_iterator::operator!=
bool operator!=(aged_container_iterator< other_is_const, OtherIterator, OtherBase > const &other) const
Definition: aged_container_iterator.h:108
beast::detail::aged_container_iterator::operator*
Base::reference operator*() const
Definition: aged_container_iterator.h:146
std::enable_if
std::iterator_traits
beast::detail::aged_container_iterator::operator--
aged_container_iterator & operator--()
Definition: aged_container_iterator.h:131
beast::aged_ordered_container
Definition: aged_container_iterator.h:29
beast::detail::aged_container_iterator::time_point
typename Iterator::value_type::stashed::time_point time_point
Definition: aged_container_iterator.h:50
beast::detail::aged_container_iterator::aged_container_iterator
friend class aged_container_iterator
Definition: aged_container_iterator.h:171
beast::detail::aged_unordered_container
Associative container where each element is also indexed by time.
Definition: aged_unordered_container.h:85
beast::detail::aged_ordered_container
Associative container where each element is also indexed by time.
Definition: aged_ordered_container.h:82
beast::detail::aged_container_iterator::operator++
aged_container_iterator operator++(int)
Definition: aged_container_iterator.h:123
beast::detail::aged_container_iterator::iterator
Iterator const & iterator() const
Definition: aged_container_iterator.h:179
std::conditional
beast::detail::aged_container_iterator::aged_container_iterator
aged_container_iterator(aged_container_iterator< other_is_const, OtherIterator, OtherBase > const &other)
Definition: aged_container_iterator.h:63
beast::detail::aged_container_iterator::aged_container_iterator
aged_container_iterator(OtherIterator const &iter)
Definition: aged_container_iterator.h:174
type_traits
beast::detail::aged_container_iterator::operator->
Base::pointer operator->() const
Definition: aged_container_iterator.h:152
beast::detail::aged_container_iterator
Definition: aged_container_iterator.h:47
beast::detail::aged_container_iterator::operator--
aged_container_iterator operator--(int)
Definition: aged_container_iterator.h:138
beast
Definition: base_uint.h:585