-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyy_vector.h
1424 lines (1179 loc) · 35.3 KB
/
yy_vector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
MIT License
Copyright (c) 2024-2025 Yafiyogi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <cstddef>
#include <algorithm>
#include <initializer_list>
#include <memory>
#include <utility>
#include "yy_bit_twiddling.h"
#include "yy_clear_action.h"
#include "yy_compare_util.h"
#include "yy_iterator_ptr.hpp"
#include "yy_ref_traits.h"
#include "yy_span_traits.h"
#include "yy_type_traits.h"
#include "yy_utility.h"
#include "yy_vector_traits.h"
namespace yafiyogi::yy_quad {
using ClearAction = yy_data::ClearAction;
namespace vector_detail {
template<typename T>
struct vector_traits final
{
using value_type = yy_traits::remove_cvr_t<T>;
using value_l_value_ref = typename yy_traits::ref_traits<value_type>::l_value_ref;
using value_const_l_value_ref = typename yy_traits::ref_traits<value_type>::const_l_value_ref;
using value_r_value_ref = typename yy_traits::ref_traits<value_type>::r_value_ref;
using value_ptr = std::add_pointer_t<value_type>;
using const_value_ptr = std::add_pointer_t<std::add_const_t<value_type>>;
using reference = std::add_lvalue_reference_t<value_type>;
using const_reference = std::add_lvalue_reference_t<std::add_const_t<value_type>>;
static constexpr ClearAction default_action = yy_data::default_clear_action_v<value_type>;
};
} // namespace vector_detail
template<typename T,
ClearAction default_action = vector_detail::vector_traits<T>::default_action>
class vector
{
public:
using traits = vector_detail::vector_traits<T>;
using value_type = typename traits::value_type;
using value_l_value_ref = typename traits::value_l_value_ref;
using value_const_l_value_ref = typename traits::value_const_l_value_ref;
using value_r_value_ref = typename traits::value_r_value_ref;
using value_ptr = typename traits::value_ptr;
using const_value_ptr = typename traits::const_value_ptr;
using reference = typename traits::reference;
using const_reference = typename traits::const_reference;
using iterator = yy_data::iterator_detail::iterator_ptr<vector>;
using const_iterator = yy_data::iterator_detail::const_iterator_ptr<vector>;
struct insert_result final
{
iterator iter{};
bool inserted = false;
};
static_assert(std::is_default_constructible_v<value_type>, "T must be default contructable.");
static_assert(std::is_destructible_v<value_type>, "T must be destructable.");
constexpr explicit vector(size_type num):
m_size(num)
{
reserve(m_size);
}
constexpr vector(std::initializer_list<value_type> p_il) noexcept
{
reserve(p_il.size());
std::move(p_il.begin(), p_il.end(), begin());
m_size = p_il.size();
}
template<typename InputIterator>
constexpr vector(InputIterator p_begin,
InputIterator p_end) noexcept
{
auto l_size = static_cast<size_type>(std::distance(p_begin, p_end));
reserve(l_size);
std::copy(p_begin, p_end, begin());
m_size = l_size;
}
constexpr vector() noexcept = default;
constexpr vector(const vector & other)
{
static_assert(std::is_copy_constructible_v<value_type>, "T must be copy constructable.");
copy(other);
}
constexpr vector(vector && other) noexcept
{
static_assert(std::is_move_constructible_v<value_type>, "T must be move constructable.");
move(std::move(other));
}
constexpr ~vector() noexcept
{
clear(ClearAction::Keep);
}
constexpr vector & operator=(const vector & other)
{
static_assert(std::is_copy_assignable_v<value_type>, "T must be copy assignable.");
copy(other);
return *this;
}
constexpr vector & operator=(vector && other) noexcept
{
move(std::move(other));
return *this;
}
[[nodiscard]]
constexpr bool operator<(const vector & other) const noexcept
{
return yy_util::less_than(*this, other);
}
template<typename type,
std::enable_if_t<yy_traits::is_container_v<type>
&& !yy_traits::is_span_v<type>>>
[[nodiscard]]
constexpr bool operator<(const type & other) const noexcept
{
static_assert(yy_traits::is_container_v<type>, "Type must be a container.");
return yy_util::less_than(*this, other);
}
template<typename type,
std::enable_if_t<yy_traits::is_container_v<type>
&& !yy_traits::is_span_v<type>>>
[[nodiscard]]
friend constexpr bool operator<(const type & a,
const vector & b) noexcept
{
static_assert(yy_traits::is_container_v<type>, "Type must be a container.");
return yy_util::less_than(a, b);
}
[[nodiscard]]
constexpr bool operator==(const vector & other) const noexcept
{
return yy_util::equal(*this, other);
}
template<typename type,
std::enable_if_t<yy_traits::is_container_v<type>
&& !yy_traits::is_span_v<type>>>
[[nodiscard]]
constexpr bool operator==(const type & other) const noexcept
{
static_assert(yy_traits::is_container_v<type>, "Type must be a container.");
return yy_util::equal(*this, other);
}
template<typename type,
std::enable_if_t<yy_traits::is_container_v<type>
&& !yy_traits::is_span_v<type>>>
[[nodiscard]]
friend constexpr bool operator==(const type & a,
const vector & b) noexcept
{
static_assert(yy_traits::is_container_v<type>, "Type must be a container.");
return yy_util::equal(a, b);
}
[[nodiscard]]
constexpr iterator begin() noexcept
{
return iterator{this, 0};
}
[[nodiscard]]
constexpr const_iterator begin() const noexcept
{
return const_iterator{this, 0};
}
[[nodiscard]]
constexpr iterator end() noexcept
{
return iterator{this, size()};
}
[[nodiscard]]
constexpr const_iterator end() const noexcept
{
return const_iterator{this, size()};
}
[[nodiscard]]
constexpr value_type & operator[](size_type pos) noexcept
{
return *(begin() + static_cast<ssize_type>(pos));
}
[[nodiscard]]
constexpr const value_type & operator[](size_type pos) const noexcept
{
return *(begin() + static_cast<ssize_type>(pos));
}
[[nodiscard]]
constexpr value_type & back()
{
if(begin() == end())
{
throw std::out_of_range("vector<T>::back(): vector is empty!");
}
return *(end() - 1);
}
[[nodiscard]]
constexpr value_const_l_value_ref back() const
{
if(begin() == end())
{
throw std::out_of_range("vector<T>::back(): vector is empty!");
}
return *(end() - 1);
}
[[nodiscard]]
constexpr value_type & front()
{
if(begin() == end())
{
throw std::out_of_range("vector<T>::front(): vector is empty!");
}
return *begin();
}
[[nodiscard]]
constexpr value_const_l_value_ref front() const
{
if(begin() == end())
{
throw std::out_of_range("vector<T>::front(): vector is empty!");
}
return *begin();
}
[[nodiscard]]
constexpr value_ptr data() noexcept
{
return raw_data() + m_offset;
}
[[nodiscard]]
constexpr const_value_ptr data() const noexcept
{
return raw_data() + m_offset;
}
[[nodiscard]]
constexpr size_type size() const noexcept
{
return m_size - m_offset;
}
[[nodiscard]]
constexpr size_type capacity() const noexcept
{
return m_capacity;
}
[[nodiscard]]
constexpr size_type offset() const noexcept
{
return m_offset;
}
[[nodiscard]]
constexpr bool empty() const noexcept
{
return size_type{0} == size();
}
[[nodiscard]]
constexpr insert_result add_empty(iterator pos)
{
auto [distance, valid] = distance_valid(pos, m_size + 1);
if(!valid)
{
return insert_result{end(), false};
}
if(m_size == m_capacity)
{
if(m_offset != 0)
{
std::move(begin(), begin() + distance, raw_data());
if(static_cast<size_type>(distance) != m_size)
{
std::move(begin() + distance, end(), raw_data() + distance + 1);
}
m_size -= m_offset;
m_offset = 0;
}
else
{
// In search of the perfect dynamic array growth factor: https://youtu.be/GZPqDvG615k?si=-UBeW34k9mIj3Njv
reserve_and_move((m_size + 1) * 2, static_cast<size_type>(distance));
// Can't use the parameter 'pos' after this point!
}
}
else
{
#if defined(__GNUC__) && ! defined(__clang__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wnonnull" // for g++ 12.3
#endif
std::move_backward(pos, end(), end() + 1);
#if defined(__GNUC__) && ! defined(__clang__)
# pragma GCC diagnostic pop
#endif
}
++m_size;
return insert_result{begin() + distance, true};
}
constexpr insert_result emplace(iterator pos,
const value_type & value)
{
insert_result result{add_empty(pos)};
if(result.inserted)
{
*result.iter = value;
}
return result;
}
constexpr insert_result emplace(iterator pos,
value_type && value)
{
insert_result result{add_empty(pos)};
if(result.inserted)
{
*result.iter = std::move(value);
}
return result;
}
template<typename ...Args>
constexpr insert_result emplace(iterator pos,
Args && ...args)
{
insert_result result{add_empty(pos)};
if(result.inserted)
{
*result.iter = value_type{std::forward<Args>(args)...};
}
return result;
}
constexpr reference emplace_back(const value_type & value)
{
auto [iter, inserted] = emplace(end(), value);
return *iter;
}
constexpr reference emplace_back(value_type && value)
{
auto [iter, inserted] = emplace(end(), std::move(value));
return *iter;
}
template<typename ...Args>
constexpr reference emplace_back(Args && ...args)
{
auto [iter, inserted] = emplace(end(), std::forward<Args>(args)...);
return *iter;
}
constexpr reference push_back(const value_type & value)
{
return emplace(end(), value);
}
constexpr reference push_back(value_type && value)
{
return emplace(end(), std::move(value));
}
constexpr void reserve(size_type new_capacity)
{
reserve_and_move(new_capacity, m_size);
}
constexpr bool erase(iterator pos,
ClearAction action = default_action) noexcept
{
bool erased = false;
if(!empty())
{
auto [distance, valid] = distance_valid(pos, m_size);
if(valid)
{
erased = true;
if(distance == static_cast<ssize_type>(m_size - 1))
{
// Erase end element.
if(ClearAction::Clear == action)
{
*pos = value_type{};
}
--m_size;
}
else if(distance == 0)
{
// Erase first element.
if(ClearAction::Clear == action)
{
*pos = value_type{};
}
++m_offset;
}
else
{
// The element is in the middle.
if(ClearAction::Clear == action)
{
std::move(pos + 1, end(), pos);
}
--m_size;
}
reset_offset_size();
}
}
return erased;
}
constexpr bool erase(iterator p_begin,
iterator p_end,
ClearAction action = default_action) noexcept
{
bool erased = false;
if(!empty())
{
ssize_type distance = p_begin - begin();
if(distance < 0)
{
p_begin = begin();
}
else if(static_cast<size_type>(distance) > m_size)
{
p_begin = end();
}
distance = p_end - p_begin;
if(distance < 0)
{
p_end = p_begin;
}
else if(static_cast<size_type>(p_end - begin()) > m_size)
{
p_end = end();
}
distance = p_end - p_begin;
if(0 != distance)
{
erased = true;
if(begin() == p_begin)
{
if(ClearAction::Clear == action)
{
for(auto range{yy_util::make_range(p_begin, p_end)};
auto & item : range)
{
item = value_type{};
}
}
m_offset += static_cast<size_type>(distance);
}
else
{
std::move(p_end, end(), p_begin);
if(ClearAction::Clear == action)
{
for(auto range{yy_util::make_range(p_end, end())};
auto & item : range)
{
item = value_type{};
}
}
m_size -= static_cast<size_type>(distance);
}
reset_offset_size();
}
}
return erased;
}
constexpr void pop_back(ClearAction action = default_action) noexcept
{
if(!empty())
{
erase(end() - 1, end(), action);
}
}
constexpr void pop_front(ClearAction action = default_action) noexcept
{
if(!empty())
{
erase(begin(), begin() + 1, action);
}
}
constexpr void copy(const vector & other,
ClearAction action = default_action)
{
if(this != &other)
{
// If other.size() > m_size, don't keep the elements as they will
// all be overwritten.
// If other.size() > m_capacity, don't keep the elements as they will
// be freed when the buffer is deallocated.
size_type start_of_clear = 0;
ClearAction clear_action = ClearAction::Keep;
// Delete the elements which are not overwritten.
if(other.size() < size())
{
start_of_clear = other.size();
clear_action = action;
}
clear(start_of_clear, clear_action);
reserve_and_move(other.size(), m_size);
m_size = other.size();
m_offset = 0;
// Copy elements from othe vector.
if(!other.empty())
{
std::copy(other.begin(), other.end(), begin());
}
}
}
void assign(const vector & other,
ClearAction action = default_action)
{
copy(other, action);
}
void assign(vector && other)
{
move(std::move(other));
}
void assign(yy_quad::const_span<value_type> other,
ClearAction action = default_action)
{
auto other_data = other.data();
auto other_size = other.size();
auto this_data = data();
auto this_size = size();
if(((other_data < this_data)
|| (other_data > (this_data + this_size)))
&& (((other_data + other_size) < this_data)
|| ((other_data + other_size) > (this_data + this_size))))
{
clear(action);
reserve(other_size);
std::copy(other.begin(), other.end(), begin());
m_size = other_size;
}
}
void append(const yy_quad::const_span<value_type> & other)
{
reserve(size() + other.size());
std::copy(other.begin(), other.end(), end());
m_size += other.size();
}
void append(vector && other)
{
reserve(size() + other.size());
std::move(other.begin(), other.end(), end());
m_size += other.size();
}
constexpr void clear(ClearAction action = default_action) noexcept
{
clear(0, action);
}
constexpr void swap(vector & other) noexcept
{
if(this != &other)
{
std::swap(m_data, other.m_data);
std::swap(m_capacity, other.m_capacity);
std::swap(m_size, other.m_size);
std::swap(m_offset, other.m_offset);
}
}
constexpr void swap(vector && other) noexcept
{
move(std::move(other));
}
private:
constexpr void move(vector && p_other) noexcept
{
if(this != &p_other)
{
m_data = std::move(p_other.m_data);
m_capacity = p_other.m_capacity;
p_other.m_capacity = 0;
m_size = p_other.m_size;
p_other.m_size = 0;
m_offset = p_other.m_offset;
p_other.m_offset = 0;
}
}
[[nodiscard]]
constexpr value_ptr raw_data() noexcept
{
return m_data.get();
}
[[nodiscard]]
constexpr const_value_ptr raw_data() const noexcept
{
return m_data.get();
}
constexpr void reset_offset_size() noexcept
{
if(m_offset == m_size)
{
// The vector is empty so reset.
m_offset = 0;
m_size = 0;
}
}
struct distance_valid_type final
{
ssize_type distance = 0;
bool valid = false;
};
constexpr distance_valid_type distance_valid(const iterator pos,
size_type max) const noexcept
{
const ssize_type distance = const_iterator{pos} - begin();
return distance_valid_type{distance,
(distance >= 0) && (static_cast<size_type>(distance) < max)};
}
constexpr void clear(size_type start,
ClearAction action = default_action) noexcept
{
if(!empty() && (ClearAction::Clear == action))
{
for(auto range{yy_util::make_range(begin() + static_cast<ssize_type>(start), end())};
auto & element : range)
{
element = value_type{};
}
}
// The vector is empty so reset.
m_size = 0;
m_offset = 0;
}
constexpr void reserve_and_move(size_type new_capacity,
size_type pos) noexcept
{
if(new_capacity > m_capacity)
{
auto new_data{std::make_unique<vector_type>(new_capacity)};
if((m_size > 0) && m_data)
{
std::move(begin(), begin() + pos, new_data.get());
if(pos != m_size)
{
std::move(begin() + pos, end(), new_data.get() + pos + 1);
}
m_size -= m_offset;
m_offset = 0;
}
m_data = std::move(new_data);
m_capacity = new_capacity;
}
}
using vector_type = value_type[];
using vector_ptr = std::unique_ptr<vector_type>;
vector_ptr m_data = nullptr;
size_type m_size = 0;
size_type m_offset = 0;
size_type m_capacity = 0;
};
template<typename T,
ClearAction default_action = vector_detail::vector_traits<T>::default_action>
class simple_vector
{
public:
using traits = vector_detail::vector_traits<T>;
using value_type = typename traits::value_type;
using value_l_value_ref = typename traits::value_l_value_ref;
using value_const_l_value_ref = typename traits::value_const_l_value_ref;
using value_r_value_ref = typename traits::value_r_value_ref;
using value_ptr = typename traits::value_ptr;
using const_value_ptr = typename traits::const_value_ptr;
using iterator = yy_data::iterator_detail::iterator_ptr<simple_vector>;
using const_iterator = yy_data::iterator_detail::const_iterator_ptr<simple_vector>;
using reference = typename traits::reference;
using const_reference = typename traits::const_reference;
struct insert_result final
{
iterator iter{};
bool inserted = false;
};
static_assert(std::is_default_constructible_v<value_type>, "T must be default contructable.");
static_assert(std::is_destructible_v<value_type>, "T must be destructable.");
constexpr explicit simple_vector(size_type num):
m_size(num)
{
reserve(m_size);
}
constexpr simple_vector(std::initializer_list<value_type> p_il) noexcept
{
reserve(p_il.size());
std::move(p_il.begin(), p_il.end(), begin());
m_size = p_il.size();
}
template<typename InputIterator>
constexpr simple_vector(InputIterator p_begin,
InputIterator p_end) noexcept
{
auto l_size = static_cast<size_type>(std::distance(p_begin, p_end));
reserve(l_size);
std::copy(p_begin, p_end, begin());
m_size = l_size;
}
constexpr simple_vector() noexcept = default;
constexpr simple_vector(const simple_vector & other)
{
static_assert(std::is_copy_constructible_v<value_type>, "T must be copy constructable.");
copy(other);
}
constexpr simple_vector(simple_vector && other) noexcept
{
static_assert(std::is_move_constructible_v<value_type>, "T must be move constructable.");
move(std::move(other));
}
constexpr ~simple_vector() noexcept
{
clear(ClearAction::Keep);
}
constexpr simple_vector & operator=(const simple_vector & other)
{
static_assert(std::is_copy_assignable_v<value_type>, "T must be copy assignable.");
copy(other);
return *this;
}
constexpr simple_vector & operator=(simple_vector && other) noexcept
{
move(std::move(other));
return *this;
}
[[nodiscard]]
constexpr bool operator<(const simple_vector & other) const noexcept
{
return yy_util::less_than(*this, other);
}
template<typename type,
std::enable_if_t<yy_traits::is_container_v<type>
&& !yy_traits::is_span_v<type>>>
[[nodiscard]]
constexpr bool operator<(const type & other) const noexcept
{
return yy_util::less_than(*this, other);
}
template<typename type,
std::enable_if_t<yy_traits::is_container_v<type>
&& !yy_traits::is_span_v<type>>>
[[nodiscard]]
friend constexpr bool operator<(const type & a,
const simple_vector & b) noexcept
{
return yy_util::less_than(a, b);
}
[[nodiscard]]
constexpr bool operator==(const simple_vector & other) const noexcept
{
return yy_util::equal(*this, other);
}
template<typename type,
std::enable_if_t<yy_traits::is_container_v<type>
&& !yy_traits::is_span_v<type>>>
[[nodiscard]]
constexpr bool operator==(const type & other) const noexcept
{
return yy_util::equal(*this, other);
}
template<typename type,
std::enable_if_t<yy_traits::is_container_v<type>
&& !yy_traits::is_span_v<type>>>
[[nodiscard]]
friend constexpr bool operator==(const type & a,
const simple_vector & b) noexcept
{
return yy_util::equal(a, b);
}
[[nodiscard]]
constexpr iterator begin() noexcept
{
return iterator{this, 0};
}
[[nodiscard]]
constexpr const_iterator begin() const noexcept
{
return const_iterator{this, 0};
}
[[nodiscard]]
constexpr iterator end() noexcept
{
return iterator{this, size()};
}
[[nodiscard]]
constexpr const_iterator end() const noexcept
{
return const_iterator{this, size()};
}
[[nodiscard]]
constexpr value_type & operator[](size_type pos) noexcept
{
return *(begin() + static_cast<ssize_type>(pos));
}
[[nodiscard]]
constexpr const value_type & operator[](size_type pos) const noexcept
{
return *(begin() + static_cast<ssize_type>(pos));
}
[[nodiscard]]
constexpr value_type & back()
{
if(begin() == end())
{
throw std::out_of_range("simple_vector<T>::back(): vector is empty!");
}
return *(data() + m_size - 1);
}
[[nodiscard]]
constexpr value_const_l_value_ref back() const
{
if(begin() == end())
{
throw std::out_of_range("simple_vector<T>::back(): vector is empty!");
}
return *(data() + m_size - 1);
}
[[nodiscard]]
constexpr value_type & front()
{
if(begin() == end())
{
throw std::out_of_range("simple_vector<T>::front(): vector is empty!");
}
return *data();
}
[[nodiscard]]
constexpr value_const_l_value_ref front() const