2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
4 * This is the base for StormByte Suite libraries.
6 * StormByte original source is dual-licensed:
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
19 * Both licenses apply only to original StormByte source in this repository.
20 * They do not cover other StormByte modules or any third-party material
21 * shipped with this repository (including everything under thirdparty/),
22 * which remains under its own license.
24 * Neither license grants any patent rights. Any patent licenses required
25 * to use this software or third-party components must be obtained separately
26 * from the patent holders.
28 * StormByte is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
33 * You should have received a copy of the GNU Lesser General Public License
34 * version 3 along with StormByte. If not, see
35 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
47 template<Type::SafeComponent Component>
48 requires requires(Component& component, const Component& readonly) {
49 typename Component::value_type;
50 { component.begin() };
54 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
56 template<bool IsConst>
57 template<bool OtherConst>
58 requires IsConst && (!OtherConst)
59 Iterable<Component>::BasicIterator<IsConst>::BasicIterator(const BasicIterator<OtherConst>& other) noexcept: m_current(other.m_current) {}
61 template<Type::SafeComponent Component>
62 requires requires(Component& component, const Component& readonly) {
63 typename Component::value_type;
64 { component.begin() };
68 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
70 template<bool IsConst>
71 Iterable<Component>::BasicIterator<IsConst>::BasicIterator(Inner current) noexcept: m_current(current) {}
73 template<Type::SafeComponent Component>
74 requires requires(Component& component, const Component& readonly) {
75 typename Component::value_type;
76 { component.begin() };
80 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
82 template<bool IsConst>
83 Iterable<Component>::BasicIterator<IsConst>::reference Iterable<Component>::BasicIterator<IsConst>::operator*() const {
87 template<Type::SafeComponent Component>
88 requires requires(Component& component, const Component& readonly) {
89 typename Component::value_type;
90 { component.begin() };
94 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
96 template<bool IsConst>
97 Iterable<Component>::BasicIterator<IsConst>& Iterable<Component>::BasicIterator<IsConst>::operator++() {
102 template<Type::SafeComponent Component>
103 requires requires(Component& component, const Component& readonly) {
104 typename Component::value_type;
105 { component.begin() };
107 { readonly.begin() };
109 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
111 template<bool IsConst>
112 Iterable<Component>::BasicIterator<IsConst> Iterable<Component>::BasicIterator<IsConst>::operator++(int) {
113 BasicIterator previous = *this;
118 template<Type::SafeComponent Component>
119 requires requires(Component& component, const Component& readonly) {
120 typename Component::value_type;
121 { component.begin() };
123 { readonly.begin() };
125 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
127 template<bool IsConst>
128 Iterable<Component>::BasicIterator<IsConst>& Iterable<Component>::BasicIterator<IsConst>::operator--() {
133 template<Type::SafeComponent Component>
134 requires requires(Component& component, const Component& readonly) {
135 typename Component::value_type;
136 { component.begin() };
138 { readonly.begin() };
140 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
142 template<bool IsConst>
143 Iterable<Component>::BasicIterator<IsConst> Iterable<Component>::BasicIterator<IsConst>::operator--(int) {
144 BasicIterator previous = *this;
149 template<Type::SafeComponent Component>
150 requires requires(Component& component, const Component& readonly) {
151 typename Component::value_type;
152 { component.begin() };
154 { readonly.begin() };
156 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
158 template<bool IsConst>
159 Iterable<Component>::BasicIterator<IsConst>& Iterable<Component>::BasicIterator<IsConst>::operator+=(difference_type offset) requires random_access {
164 template<Type::SafeComponent Component>
165 requires requires(Component& component, const Component& readonly) {
166 typename Component::value_type;
167 { component.begin() };
169 { readonly.begin() };
171 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
173 template<bool IsConst>
174 Iterable<Component>::BasicIterator<IsConst>& Iterable<Component>::BasicIterator<IsConst>::operator-=(difference_type offset) requires random_access {
179 template<Type::SafeComponent Component>
180 requires requires(Component& component, const Component& readonly) {
181 typename Component::value_type;
182 { component.begin() };
184 { readonly.begin() };
186 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
188 template<bool IsConst>
189 Iterable<Component>::BasicIterator<IsConst>::reference Iterable<Component>::BasicIterator<IsConst>::operator[](difference_type offset) const requires random_access {
190 return m_current[offset];
193 template<Type::SafeComponent Component>
194 requires requires(Component& component, const Component& readonly) {
195 typename Component::value_type;
196 { component.begin() };
198 { readonly.begin() };
200 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
202 template<bool IsConst>
203 Iterable<Component>::BasicIterator<IsConst> Iterable<Component>::BasicIterator<IsConst>::operator+(difference_type offset) const requires random_access {
204 BasicIterator advanced = *this;
209 template<Type::SafeComponent Component>
210 requires requires(Component& component, const Component& readonly) {
211 typename Component::value_type;
212 { component.begin() };
214 { readonly.begin() };
216 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
218 template<bool IsConst>
219 Iterable<Component>::BasicIterator<IsConst> Iterable<Component>::BasicIterator<IsConst>::operator-(difference_type offset) const requires random_access {
220 BasicIterator retreated = *this;
225 template<Type::SafeComponent Component>
226 requires requires(Component& component, const Component& readonly) {
227 typename Component::value_type;
228 { component.begin() };
230 { readonly.begin() };
232 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
234 template<bool IsConst>
235 template<bool OtherConst>
236 Iterable<Component>::BasicIterator<IsConst>::difference_type Iterable<Component>::BasicIterator<IsConst>::operator-(const BasicIterator<OtherConst>& other) const requires random_access {
237 return m_current - other.m_current;
240 template<Type::SafeComponent Component>
241 requires requires(Component& component, const Component& readonly) {
242 typename Component::value_type;
243 { component.begin() };
245 { readonly.begin() };
247 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
249 template<bool IsConst>
250 template<bool OtherConst>
251 bool Iterable<Component>::BasicIterator<IsConst>::operator==(const BasicIterator<OtherConst>& other) const {
252 return m_current == other.m_current;
255 template<Type::SafeComponent Component>
256 requires requires(Component& component, const Component& readonly) {
257 typename Component::value_type;
258 { component.begin() };
260 { readonly.begin() };
262 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
264 template<bool IsConst>
265 template<bool OtherConst>
266 bool Iterable<Component>::BasicIterator<IsConst>::operator<(const BasicIterator<OtherConst>& other) const requires random_access {
267 return m_current < other.m_current;
270 template<Type::SafeComponent Component>
271 requires requires(Component& component, const Component& readonly) {
272 typename Component::value_type;
273 { component.begin() };
275 { readonly.begin() };
277 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
279 template<bool IsConst>
280 template<bool OtherConst>
281 bool Iterable<Component>::BasicIterator<IsConst>::operator>(const BasicIterator<OtherConst>& other) const requires random_access {
282 return other < *this;
285 template<Type::SafeComponent Component>
286 requires requires(Component& component, const Component& readonly) {
287 typename Component::value_type;
288 { component.begin() };
290 { readonly.begin() };
292 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
294 template<bool IsConst>
295 template<bool OtherConst>
296 bool Iterable<Component>::BasicIterator<IsConst>::operator<=(const BasicIterator<OtherConst>& other) const requires random_access {
297 return !(other < *this);
300 template<Type::SafeComponent Component>
301 requires requires(Component& component, const Component& readonly) {
302 typename Component::value_type;
303 { component.begin() };
305 { readonly.begin() };
307 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
309 template<bool IsConst>
310 template<bool OtherConst>
311 bool Iterable<Component>::BasicIterator<IsConst>::operator>=(const BasicIterator<OtherConst>& other) const requires random_access {
312 return !(*this < other);
315 template<Type::SafeComponent Component>
316 requires requires(Component& component, const Component& readonly) {
317 typename Component::value_type;
318 { component.begin() };
320 { readonly.begin() };
322 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
324 Iterable<Component>::Iterable(container_type container) noexcept: m_container(std::move(container)) {}
326 template<Type::SafeComponent Component>
327 requires requires(Component& component, const Component& readonly) {
328 typename Component::value_type;
329 { component.begin() };
331 { readonly.begin() };
333 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
335 Iterable<Component>::iterator Iterable<Component>::begin() noexcept {
336 return iterator(m_container.begin());
339 template<Type::SafeComponent Component>
340 requires requires(Component& component, const Component& readonly) {
341 typename Component::value_type;
342 { component.begin() };
344 { readonly.begin() };
346 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
348 Iterable<Component>::iterator Iterable<Component>::end() noexcept {
349 return iterator(m_container.end());
352 template<Type::SafeComponent Component>
353 requires requires(Component& component, const Component& readonly) {
354 typename Component::value_type;
355 { component.begin() };
357 { readonly.begin() };
359 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
361 Iterable<Component>::const_iterator Iterable<Component>::begin() const noexcept {
362 return const_iterator(m_container.begin());
365 template<Type::SafeComponent Component>
366 requires requires(Component& component, const Component& readonly) {
367 typename Component::value_type;
368 { component.begin() };
370 { readonly.begin() };
372 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
374 Iterable<Component>::const_iterator Iterable<Component>::end() const noexcept {
375 return const_iterator(m_container.end());
378 template<Type::SafeComponent Component>
379 requires requires(Component& component, const Component& readonly) {
380 typename Component::value_type;
381 { component.begin() };
383 { readonly.begin() };
385 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
387 Iterable<Component>::const_iterator Iterable<Component>::cbegin() const noexcept {
391 template<Type::SafeComponent Component>
392 requires requires(Component& component, const Component& readonly) {
393 typename Component::value_type;
394 { component.begin() };
396 { readonly.begin() };
398 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
400 Iterable<Component>::const_iterator Iterable<Component>::cend() const noexcept {
404 template<Type::SafeComponent Component>
405 requires requires(Component& component, const Component& readonly) {
406 typename Component::value_type;
407 { component.begin() };
409 { readonly.begin() };
411 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
413 bool Iterable<Component>::empty() const noexcept {
414 return m_container.empty();
417 template<Type::SafeComponent Component>
418 requires requires(Component& component, const Component& readonly) {
419 typename Component::value_type;
420 { component.begin() };
422 { readonly.begin() };
424 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
426 Iterable<Component>::size_type Iterable<Component>::size() const noexcept {
427 return static_cast<size_type>(m_container.size());
430 template<Type::SafeComponent Component>
431 requires requires(Component& component, const Component& readonly) {
432 typename Component::value_type;
433 { component.begin() };
435 { readonly.begin() };
437 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
439 Iterable<Component>::container_type& Iterable<Component>::Container() noexcept {
443 template<Type::SafeComponent Component>
444 requires requires(Component& component, const Component& readonly) {
445 typename Component::value_type;
446 { component.begin() };
448 { readonly.begin() };
450 { readonly.size() } -> Type::ConvertibleTo<std::size_t>;
452 const Iterable<Component>::container_type& Iterable<Component>::Container() const noexcept {