qxLib
base_iterator.inl
Go to the documentation of this file.
1 /**
2 
3  @file base_iterator.inl
4  @author Khrapov
5  @date 14.10.2026
6  @copyright (c) Nick Khrapov, 2026. All right reserved.
7 
8 **/
9 
10 namespace qx
11 {
12 
13 template<class container_t>
14 constexpr base_iterator<container_t>::operator void*() noexcept
15 {
16  return &(*m_pContainer).at(m_nIndex);
17 }
18 
19 template<class container_t>
20 constexpr void base_iterator<container_t>::shift(difference_type nShift) noexcept
21 {
22  m_nIndex += nShift;
23 }
24 
25 template<class container_t>
26 constexpr decltype(auto) base_iterator<container_t>::get(difference_type nShift) const noexcept
27 {
28  return (*m_pContainer).at(m_nIndex + nShift);
29 }
30 
31 template<class container_t>
32 constexpr typename base_iterator<container_t>::size_type base_iterator<container_t>::get_index() const noexcept
33 {
34  return m_nIndex;
35 }
36 
37 template<class container_t, class derived_t>
38 template<class iterator_t>
39  requires derived_from_template_c<iterator_t, base_iterator>
40 constexpr typename base_forward_iterator<container_t, derived_t>::super_type::difference_type base_forward_iterator<
41  container_t,
42  derived_t>::operator-(const iterator_t& r) const noexcept
43 {
44  return static_cast<typename super_type::difference_type>(super_type::get_index() - r.get_index());
45 }
46 
47 template<class container_t, class derived_t>
48 constexpr bool base_forward_iterator<container_t, derived_t>::operator<(const base_forward_iterator& r) const noexcept
49 {
50  return super_type::get_index() < r.get_index();
51 }
52 
53 template<class container_t, class derived_t>
54 constexpr bool base_forward_iterator<container_t, derived_t>::operator<=(const base_forward_iterator& r) const noexcept
55 {
56  return super_type::get_index() <= r.get_index();
57 }
58 
59 template<class container_t, class derived_t>
60 constexpr bool base_forward_iterator<container_t, derived_t>::operator>(const base_forward_iterator& r) const noexcept
61 {
62  return super_type::get_index() > r.get_index();
63 }
64 
65 template<class container_t, class derived_t>
66 constexpr bool base_forward_iterator<container_t, derived_t>::operator>=(const base_forward_iterator& r) const noexcept
67 {
68  return super_type::get_index() >= r.get_index();
69 }
70 
71 template<class container_t, class derived_t>
72 constexpr bool base_forward_iterator<container_t, derived_t>::operator!=(const base_forward_iterator& r) const noexcept
73 {
74  return super_type::get_index() != r.get_index();
75 }
76 
77 template<class container_t, class derived_t>
78 constexpr bool base_forward_iterator<container_t, derived_t>::operator==(const base_forward_iterator& r) const noexcept
79 {
80  return super_type::get_index() == r.get_index();
81 }
82 
83 template<class container_t, class derived_t>
84 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type& base_forward_iterator<
85  container_t,
86  derived_t>::operator++() noexcept
87 {
88  super_type::shift(1);
89  return static_cast<decayed_derived_type&>(*this);
90 }
91 
92 template<class container_t, class derived_t>
93 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type& base_forward_iterator<
94  container_t,
95  derived_t>::operator--() noexcept
96 {
97  super_type::shift(-1);
98  return static_cast<decayed_derived_type&>(*this);
99 }
100 
101 template<class container_t, class derived_t>
102 [[nodiscard]] constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type
103  base_forward_iterator<container_t, derived_t>::operator++(int) noexcept
104 {
105  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
106  super_type::shift(1);
107  return r;
108 }
109 
110 template<class container_t, class derived_t>
111 [[nodiscard]] constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type
112  base_forward_iterator<container_t, derived_t>::operator--(int) noexcept
113 {
114  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
115  super_type::shift(-1);
116  return r;
117 }
118 
119 template<class container_t, class derived_t>
120 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type& base_forward_iterator<
121  container_t,
122  derived_t>::operator+=(typename super_type::difference_type n) noexcept
123 {
124  super_type::shift(n);
125  return static_cast<decayed_derived_type&>(*this);
126 }
127 
128 template<class container_t, class derived_t>
129 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type& base_forward_iterator<
130  container_t,
131  derived_t>::operator-=(typename super_type::difference_type n) noexcept
132 {
133  super_type::shift(-n);
134  return static_cast<decayed_derived_type&>(*this);
135 }
136 
137 template<class container_t, class derived_t>
138 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type base_forward_iterator<
139  container_t,
140  derived_t>::operator+(typename super_type::difference_type n) const noexcept
141 {
142  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
143  return r += n;
144 }
145 
146 template<class container_t, class derived_t>
147 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type base_forward_iterator<
148  container_t,
149  derived_t>::operator-(typename super_type::difference_type n) const noexcept
150 {
151  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
152  return r -= n;
153 }
154 
155 template<class iterator_t>
156  requires derived_from_template_c<iterator_t, base_forward_iterator>
157 constexpr iterator_t operator+(typename iterator_t::size_type n, iterator_t it) noexcept
158 {
159  return it += n;
160 }
161 
162 template<class container_t, class derived_t>
163 template<class iterator_t>
164  requires derived_from_template_c<iterator_t, base_iterator>
165 constexpr typename base_reverse_iterator<container_t, derived_t>::super_type::difference_type base_reverse_iterator<
166  container_t,
167  derived_t>::operator-(const iterator_t& r) const noexcept
168 {
169  return static_cast<typename super_type::difference_type>(r.get_index() - super_type::get_index());
170 }
171 
172 template<class container_t, class derived_t>
173 constexpr bool base_reverse_iterator<container_t, derived_t>::operator<(const base_reverse_iterator& r) const noexcept
174 {
175  return super_type::get_index() + 1 > r.get_index() + 1;
176 }
177 
178 template<class container_t, class derived_t>
179 constexpr bool base_reverse_iterator<container_t, derived_t>::operator<=(const base_reverse_iterator& r) const noexcept
180 {
181  return super_type::get_index() + 1 >= r.get_index() + 1;
182 }
183 
184 template<class container_t, class derived_t>
185 constexpr bool base_reverse_iterator<container_t, derived_t>::operator>(const base_reverse_iterator& r) const noexcept
186 {
187  return super_type::get_index() + 1 < r.get_index() + 1;
188 }
189 
190 template<class container_t, class derived_t>
191 constexpr bool base_reverse_iterator<container_t, derived_t>::operator>=(const base_reverse_iterator& r) const noexcept
192 {
193  return super_type::get_index() + 1 <= r.get_index() + 1;
194 }
195 
196 template<class container_t, class derived_t>
197 constexpr bool base_reverse_iterator<container_t, derived_t>::operator!=(const base_reverse_iterator& r) const noexcept
198 {
199  return super_type::get_index() + 1 != r.get_index() + 1;
200 }
201 
202 template<class container_t, class derived_t>
203 constexpr bool base_reverse_iterator<container_t, derived_t>::operator==(const base_reverse_iterator& r) const noexcept
204 {
205  return super_type::get_index() + 1 == r.get_index() + 1;
206 }
207 
208 template<class container_t, class derived_t>
209 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type& base_reverse_iterator<
210  container_t,
211  derived_t>::operator++() noexcept
212 {
213  super_type::shift(-1);
214  return static_cast<decayed_derived_type&>(*this);
215 }
216 
217 template<class container_t, class derived_t>
218 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type& base_reverse_iterator<
219  container_t,
220  derived_t>::operator--() noexcept
221 {
222  super_type::shift(1);
223  return static_cast<decayed_derived_type&>(*this);
224 }
225 
226 template<class container_t, class derived_t>
227 [[nodiscard]] constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type
228  base_reverse_iterator<container_t, derived_t>::operator++(int) noexcept
229 {
230  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
231  super_type::shift(-1);
232  return r;
233 }
234 
235 template<class container_t, class derived_t>
236 [[nodiscard]] constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type
237  base_reverse_iterator<container_t, derived_t>::operator--(int) noexcept
238 {
239  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
240  super_type::shift(1);
241  return r;
242 }
243 
244 template<class container_t, class derived_t>
245 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type& base_reverse_iterator<
246  container_t,
247  derived_t>::operator+=(typename super_type::difference_type n) noexcept
248 {
249  super_type::shift(-n);
250  return static_cast<decayed_derived_type&>(*this);
251 }
252 
253 template<class container_t, class derived_t>
254 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type& base_reverse_iterator<
255  container_t,
256  derived_t>::operator-=(typename super_type::difference_type n) noexcept
257 {
258  super_type::shift(n);
259  return static_cast<decayed_derived_type&>(*this);
260 }
261 
262 template<class container_t, class derived_t>
263 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type base_reverse_iterator<
264  container_t,
265  derived_t>::operator+(typename super_type::difference_type n) const noexcept
266 {
267  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
268  return r += n;
269 }
270 
271 template<class container_t, class derived_t>
272 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type base_reverse_iterator<
273  container_t,
274  derived_t>::operator-(typename super_type::difference_type n) const noexcept
275 {
276  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
277  return r -= n;
278 }
279 
280 template<class iterator_t>
281  requires derived_from_template_c<iterator_t, base_reverse_iterator>
282 constexpr iterator_t operator+(typename iterator_t::size_type n, iterator_t it) noexcept
283 {
284  return it += n;
285 }
286 
287 } // namespace qx
requires(same_variadic_args_v< args_t... >) const expr auto coalesce(args_t &&... args)
Coalesce function, C# a ?? b analogue.
Definition: coalesce.inl:57