tetengo 1.8.2
A multipurpose library set
Loading...
Searching...
No Matches
trie_iterator.hpp
Go to the documentation of this file.
1
7#if !defined(TETENGO_TRIE_TRIEITERATOR_HPP)
8#define TETENGO_TRIE_TRIEITERATOR_HPP
9
10#include <any>
11#include <iterator>
12#include <utility>
13
14#include <boost/stl_interfaces/iterator_interface.hpp>
15
17
18
19namespace tetengo::trie
20{
21 class storage;
22
23
28 {
29 public:
30 // types
31
32 // constructors and destructor
33
40 trie_iterator_impl(double_array_iterator double_array_iterator_, storage& storage_);
41
48
49
50 // functions
51
57 [[nodiscard]] const std::any& operator*() const;
58
64 [[nodiscard]] std::any& operator*();
65
75 friend bool operator==(const trie_iterator_impl& one, const trie_iterator_impl& another);
76
83
84
85 private:
86 // variables
87
88 double_array_iterator m_double_array_iterator;
89
90 storage* m_p_storage;
91 };
92
93
99 template <typename Value>
101 public boost::stl_interfaces::iterator_interface<trie_iterator<Value>, std ::forward_iterator_tag, Value>
102 {
103 public:
104 // types
105
107 using value_type = Value;
108
109
110 // constructors and destructor
111
117 trie_iterator(trie_iterator_impl&& impl) : m_impl{ std::move(impl) } {}
118
119
120 // functions
121
127 [[nodiscard]] const value_type& operator*() const
128 {
129 return *std::any_cast<value_type>(&*m_impl);
130 }
131
137 [[nodiscard]] value_type& operator*()
138 {
139 return *std::any_cast<value_type>(&*m_impl);
140 }
141
147 [[nodiscard]] const value_type* operator->() const
148 {
149 return std::any_cast<value_type>(&*m_impl);
150 }
151
157 [[nodiscard]] value_type* operator->()
158 {
159 return std::any_cast<value_type>(&*m_impl);
160 }
161
171 friend bool operator==(const trie_iterator& one, const trie_iterator& another)
172 {
173 return one.m_impl == another.m_impl;
174 }
175
182 {
183 ++m_impl;
184 return *this;
185 }
186
193 {
194 trie_iterator original{ *this };
195 ++(*this);
196 return original;
197 }
198
199
200 private:
201 // variables
202
203 trie_iterator_impl m_impl;
204 };
205
206
207}
208
209
210#endif
A double array iterator.
Definition double_array_iterator.hpp:32
A storage.
Definition storage.hpp:28
An implementation of trie iterator.
Definition trie_iterator.hpp:28
trie_iterator_impl(double_array_iterator double_array_iterator_, storage &storage_)
Creates an iterator.
std::any & operator*()
Dereferences the iterator.
trie_iterator_impl & operator++()
Increments the iterator.
trie_iterator_impl()
Creates an iterator.
friend bool operator==(const trie_iterator_impl &one, const trie_iterator_impl &another)
Returns true when one iterator is equal to another.
const std::any & operator*() const
Dereferences the iterator.
A trie iterator.
Definition trie_iterator.hpp:102
friend bool operator==(const trie_iterator &one, const trie_iterator &another)
Returns true when one iterator is equal to another.
Definition trie_iterator.hpp:171
value_type & operator*()
Dereferences the iterator.
Definition trie_iterator.hpp:137
value_type * operator->()
Returns the pointer to the value.
Definition trie_iterator.hpp:157
Value value_type
The value type.
Definition trie_iterator.hpp:107
trie_iterator & operator++()
Increments the iterator.
Definition trie_iterator.hpp:181
trie_iterator(trie_iterator_impl &&impl)
Creates an iterator.
Definition trie_iterator.hpp:117
const value_type * operator->() const
Returns the pointer to the value.
Definition trie_iterator.hpp:147
trie_iterator operator++(int)
Postincrements the iterator.
Definition trie_iterator.hpp:192
const value_type & operator*() const
Dereferences the iterator.
Definition trie_iterator.hpp:127
A double array iterator.
A trie library.