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 auto base_iterator<container_t>::get_address() const noexcept
33 {
34  auto pData = m_pContainer->data();
35  return pData ? pData + m_nIndex : pData;
36 }
37 
38 template<class container_t>
39 constexpr typename base_iterator<container_t>::size_type base_iterator<container_t>::get_index() const noexcept
40 {
41  return m_nIndex;
42 }
43 
44 template<class container_t, class derived_t>
45 template<class iterator_t>
46  requires derived_from_template_c<iterator_t, base_iterator>
47 constexpr typename base_forward_iterator<container_t, derived_t>::super_type::difference_type base_forward_iterator<
48  container_t,
49  derived_t>::operator-(const iterator_t& r) const noexcept
50 {
51  return static_cast<typename super_type::difference_type>(super_type::get_index() - r.get_index());
52 }
53 
54 template<class container_t, class derived_t>
55 constexpr bool base_forward_iterator<container_t, derived_t>::operator<(const base_forward_iterator& r) const noexcept
56 {
57  return super_type::get_index() < r.get_index();
58 }
59 
60 template<class container_t, class derived_t>
61 constexpr bool base_forward_iterator<container_t, derived_t>::operator<=(const base_forward_iterator& r) const noexcept
62 {
63  return super_type::get_index() <= r.get_index();
64 }
65 
66 template<class container_t, class derived_t>
67 constexpr bool base_forward_iterator<container_t, derived_t>::operator>(const base_forward_iterator& r) const noexcept
68 {
69  return super_type::get_index() > r.get_index();
70 }
71 
72 template<class container_t, class derived_t>
73 constexpr bool base_forward_iterator<container_t, derived_t>::operator>=(const base_forward_iterator& r) const noexcept
74 {
75  return super_type::get_index() >= r.get_index();
76 }
77 
78 template<class container_t, class derived_t>
79 constexpr bool base_forward_iterator<container_t, derived_t>::operator!=(const base_forward_iterator& r) const noexcept
80 {
81  return super_type::get_index() != r.get_index();
82 }
83 
84 template<class container_t, class derived_t>
85 constexpr bool base_forward_iterator<container_t, derived_t>::operator==(const base_forward_iterator& r) const noexcept
86 {
87  return super_type::get_index() == r.get_index();
88 }
89 
90 template<class container_t, class derived_t>
91 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type& base_forward_iterator<
92  container_t,
93  derived_t>::operator++() noexcept
94 {
95  super_type::shift(1);
96  return static_cast<decayed_derived_type&>(*this);
97 }
98 
99 template<class container_t, class derived_t>
100 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type& base_forward_iterator<
101  container_t,
102  derived_t>::operator--() noexcept
103 {
104  super_type::shift(-1);
105  return static_cast<decayed_derived_type&>(*this);
106 }
107 
108 template<class container_t, class derived_t>
109 [[nodiscard]] constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type
110  base_forward_iterator<container_t, derived_t>::operator++(int) noexcept
111 {
112  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
113  super_type::shift(1);
114  return r;
115 }
116 
117 template<class container_t, class derived_t>
118 [[nodiscard]] constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type
119  base_forward_iterator<container_t, derived_t>::operator--(int) noexcept
120 {
121  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
122  super_type::shift(-1);
123  return r;
124 }
125 
126 template<class container_t, class derived_t>
127 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type& base_forward_iterator<
128  container_t,
129  derived_t>::operator+=(typename super_type::difference_type n) noexcept
130 {
131  super_type::shift(n);
132  return static_cast<decayed_derived_type&>(*this);
133 }
134 
135 template<class container_t, class derived_t>
136 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type& base_forward_iterator<
137  container_t,
138  derived_t>::operator-=(typename super_type::difference_type n) noexcept
139 {
140  super_type::shift(-n);
141  return static_cast<decayed_derived_type&>(*this);
142 }
143 
144 template<class container_t, class derived_t>
145 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type base_forward_iterator<
146  container_t,
147  derived_t>::operator+(typename super_type::difference_type n) const noexcept
148 {
149  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
150  return r += n;
151 }
152 
153 template<class container_t, class derived_t>
154 constexpr typename base_forward_iterator<container_t, derived_t>::decayed_derived_type base_forward_iterator<
155  container_t,
156  derived_t>::operator-(typename super_type::difference_type n) const noexcept
157 {
158  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
159  return r -= n;
160 }
161 
162 template<class iterator_t>
163  requires derived_from_template_c<iterator_t, base_forward_iterator>
164 constexpr iterator_t operator+(typename iterator_t::size_type n, iterator_t it) noexcept
165 {
166  return it += n;
167 }
168 
169 template<class container_t, class derived_t>
170 template<class iterator_t>
171  requires derived_from_template_c<iterator_t, base_iterator>
172 constexpr typename base_reverse_iterator<container_t, derived_t>::super_type::difference_type base_reverse_iterator<
173  container_t,
174  derived_t>::operator-(const iterator_t& r) const noexcept
175 {
176  return static_cast<typename super_type::difference_type>(r.get_index() - super_type::get_index());
177 }
178 
179 template<class container_t, class derived_t>
180 constexpr bool base_reverse_iterator<container_t, derived_t>::operator<(const base_reverse_iterator& r) const noexcept
181 {
182  return super_type::get_index() + 1 > r.get_index() + 1;
183 }
184 
185 template<class container_t, class derived_t>
186 constexpr bool base_reverse_iterator<container_t, derived_t>::operator<=(const base_reverse_iterator& r) const noexcept
187 {
188  return super_type::get_index() + 1 >= r.get_index() + 1;
189 }
190 
191 template<class container_t, class derived_t>
192 constexpr bool base_reverse_iterator<container_t, derived_t>::operator>(const base_reverse_iterator& r) const noexcept
193 {
194  return super_type::get_index() + 1 < r.get_index() + 1;
195 }
196 
197 template<class container_t, class derived_t>
198 constexpr bool base_reverse_iterator<container_t, derived_t>::operator>=(const base_reverse_iterator& r) const noexcept
199 {
200  return super_type::get_index() + 1 <= r.get_index() + 1;
201 }
202 
203 template<class container_t, class derived_t>
204 constexpr bool base_reverse_iterator<container_t, derived_t>::operator!=(const base_reverse_iterator& r) const noexcept
205 {
206  return super_type::get_index() + 1 != r.get_index() + 1;
207 }
208 
209 template<class container_t, class derived_t>
210 constexpr bool base_reverse_iterator<container_t, derived_t>::operator==(const base_reverse_iterator& r) const noexcept
211 {
212  return super_type::get_index() + 1 == r.get_index() + 1;
213 }
214 
215 template<class container_t, class derived_t>
216 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type& base_reverse_iterator<
217  container_t,
218  derived_t>::operator++() noexcept
219 {
220  super_type::shift(-1);
221  return static_cast<decayed_derived_type&>(*this);
222 }
223 
224 template<class container_t, class derived_t>
225 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type& base_reverse_iterator<
226  container_t,
227  derived_t>::operator--() noexcept
228 {
229  super_type::shift(1);
230  return static_cast<decayed_derived_type&>(*this);
231 }
232 
233 template<class container_t, class derived_t>
234 [[nodiscard]] constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type
235  base_reverse_iterator<container_t, derived_t>::operator++(int) noexcept
236 {
237  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
238  super_type::shift(-1);
239  return r;
240 }
241 
242 template<class container_t, class derived_t>
243 [[nodiscard]] constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type
244  base_reverse_iterator<container_t, derived_t>::operator--(int) noexcept
245 {
246  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
247  super_type::shift(1);
248  return r;
249 }
250 
251 template<class container_t, class derived_t>
252 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type& base_reverse_iterator<
253  container_t,
254  derived_t>::operator+=(typename super_type::difference_type n) noexcept
255 {
256  super_type::shift(-n);
257  return static_cast<decayed_derived_type&>(*this);
258 }
259 
260 template<class container_t, class derived_t>
261 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type& base_reverse_iterator<
262  container_t,
263  derived_t>::operator-=(typename super_type::difference_type n) noexcept
264 {
265  super_type::shift(n);
266  return static_cast<decayed_derived_type&>(*this);
267 }
268 
269 template<class container_t, class derived_t>
270 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type base_reverse_iterator<
271  container_t,
272  derived_t>::operator+(typename super_type::difference_type n) const noexcept
273 {
274  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
275  return r += n;
276 }
277 
278 template<class container_t, class derived_t>
279 constexpr typename base_reverse_iterator<container_t, derived_t>::decayed_derived_type base_reverse_iterator<
280  container_t,
281  derived_t>::operator-(typename super_type::difference_type n) const noexcept
282 {
283  decayed_derived_type r(static_cast<const decayed_derived_type&>(*this));
284  return r -= n;
285 }
286 
287 template<class iterator_t>
288  requires derived_from_template_c<iterator_t, base_reverse_iterator>
289 constexpr iterator_t operator+(typename iterator_t::size_type n, iterator_t it) noexcept
290 {
291  return it += n;
292 }
293 
294 } // 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