/
entities.hpp
1215 lines (1025 loc) · 45.2 KB
/
entities.hpp
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
//----------------------------------------------------------------------------------------------------------------------
// This file is a part of marzer/soagen and is subject to the the terms of the MIT license.
// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
// See https://github.com/marzer/soagen/blob/master/LICENSE for the full license text.
// SPDX-License-Identifier: MIT
//----------------------------------------------------------------------------------------------------------------------
// This file was generated by soagen v0.7.0 - do not modify it directly
// https://marzer.github.io/soagen
//----------------------------------------------------------------------------------------------------------------------
#pragma once
/// @file
/// @brief Contains the definition of soagen::examples::entities.
///
/// @note The code and documentation in this file were generated by soagen - https://marzer.github.io/soagen
#include <soagen.hpp>
#if SOAGEN_VERSION_MAJOR != 0 || SOAGEN_VERSION_MINOR < 7
#error soagen version mismatch - expected v0.7.X
#endif
SOAGEN_DISABLE_WARNINGS;
#include <string>
SOAGEN_ENABLE_WARNINGS;
SOAGEN_PUSH_WARNINGS;
SOAGEN_DISABLE_SPAM_WARNINGS;
#if SOAGEN_MSVC
#pragma inline_recursion(on)
#endif
#if SOAGEN_MSVC_LIKE
#pragma push_macro("min")
#pragma push_macro("max")
#undef min
#undef max
#endif
//----------------------------------------------------------------------------------------------------------------------
// doxygen safeguards
//----------------------------------------------------------------------------------------------------------------------
#if defined(DOXYGEN) || defined(__DOXYGEN) || defined(__DOXYGEN__) || defined(__doxygen__) || defined(__POXY__) \
|| defined(__poxy__)
#ifndef SOAGEN_CONSTRAINED_TEMPLATE
#define SOAGEN_CONSTRAINED_TEMPLATE(cond, ...) template <__VA_ARGS__>
#endif
#ifndef SOAGEN_DOXYGEN
#define SOAGEN_DOXYGEN 1
#endif
#ifndef SOAGEN_MAKE_NAME
#define SOAGEN_MAKE_NAME(...) static_assert(true)
#endif
#ifndef SOAGEN_MAKE_NAMED_COLUMN
#define SOAGEN_MAKE_NAMED_COLUMN(...) static_assert(true)
#endif
#ifndef SOAGEN_NODISCARD
#define SOAGEN_NODISCARD
#endif
#ifndef SOAGEN_NODISCARD_CTOR
#define SOAGEN_NODISCARD_CTOR
#endif
#ifndef SOAGEN_INLINE_GETTER
#define SOAGEN_INLINE_GETTER inline
#endif
#ifndef SOAGEN_PURE_GETTER
#define SOAGEN_PURE_GETTER
#endif
#ifndef SOAGEN_PURE_INLINE_GETTER
#define SOAGEN_PURE_INLINE_GETTER inline
#endif
#ifndef SOAGEN_ALWAYS_INLINE
#define SOAGEN_ALWAYS_INLINE inline
#endif
#ifndef SOAGEN_CPP20_CONSTEXPR
#define SOAGEN_CPP20_CONSTEXPR constexpr
#endif
#ifndef SOAGEN_HIDDEN
#define SOAGEN_HIDDEN(...)
#endif
#ifndef SOAGEN_HIDDEN_BASE
#define SOAGEN_HIDDEN_BASE(...)
#endif
#ifndef SOAGEN_HIDDEN_CONSTRAINT
#define SOAGEN_HIDDEN_CONSTRAINT(...)
#endif
#ifndef SOAGEN_HIDDEN_PARAM
#define SOAGEN_HIDDEN_PARAM(...)
#endif
#ifndef SOAGEN_ENABLE_IF_T
#define SOAGEN_ENABLE_IF_T(T, ...) T
#endif
#ifndef SOAGEN_ENABLE_IF
#define SOAGEN_ENABLE_IF(...)
#endif
#ifndef SOAGEN_REQUIRES
#define SOAGEN_REQUIRES(...)
#endif
#ifndef SOAGEN_EMPTY_BASES
#define SOAGEN_EMPTY_BASES
#endif
#ifndef SOAGEN_COLUMN
#define SOAGEN_COLUMN(...)
#endif
#if !defined(POXY_IMPLEMENTATION_DETAIL) && !(defined(__POXY__) || defined(__poxy__))
#define POXY_IMPLEMENTATION_DETAIL(...) __VA_ARGS__
#endif
#endif // doxygen
//----------------------------------------------------------------------------------------------------------------------
// forward declarations + soagen internal boilerplate
//----------------------------------------------------------------------------------------------------------------------
/// @cond
// clang-format off
namespace soagen::examples
{
class entities;
}
namespace soagen::detail
{
#ifndef SOAGEN_NAME_id
#define SOAGEN_NAME_id
SOAGEN_MAKE_NAME(id);
#endif
#ifndef SOAGEN_NAME_name
#define SOAGEN_NAME_name
SOAGEN_MAKE_NAME(name);
#endif
#ifndef SOAGEN_NAME_orient
#define SOAGEN_NAME_orient
SOAGEN_MAKE_NAME(orient);
#endif
#ifndef SOAGEN_NAME_pos
#define SOAGEN_NAME_pos
SOAGEN_MAKE_NAME(pos);
#endif
}
namespace soagen_struct_impl_soagen_examples_entities
{
SOAGEN_DISABLE_WARNINGS;
using namespace soagen::examples;
SOAGEN_ENABLE_WARNINGS;
using soagen_table_traits_type = soagen::table_traits<
/* id */ soagen::column_traits<unsigned>,
/* name */ soagen::column_traits<std::string>,
/* pos */ soagen::column_traits<vec3, soagen::max(std::size_t{ 32u }, alignof(vec3))>,
/* orient */ soagen::column_traits<quaternion>>;
using soagen_allocator_type = soagen::allocator;
}
namespace soagen::detail
{
SOAGEN_MAKE_NAMED_COLUMN(soagen::examples::entities, 0, id);
SOAGEN_MAKE_NAMED_COLUMN(soagen::examples::entities, 1, name);
SOAGEN_MAKE_NAMED_COLUMN(soagen::examples::entities, 2, pos);
SOAGEN_MAKE_NAMED_COLUMN(soagen::examples::entities, 3, orient);
template <>
struct is_soa_<soagen::examples::entities> : std::true_type
{};
template <>
struct table_traits_type_<soagen::examples::entities>
{
using type = soagen_struct_impl_soagen_examples_entities::soagen_table_traits_type;
};
template <>
struct allocator_type_<soagen::examples::entities>
{
using type = soagen_struct_impl_soagen_examples_entities::soagen_allocator_type;
};
template <>
struct table_type_<soagen::examples::entities>
{
using type = table<table_traits_type<soagen::examples::entities>, allocator_type<soagen::examples::entities>>;
};
}
// clang-format on
/// @endcond
//----------------------------------------------------------------------------------------------------------------------
// entities
//----------------------------------------------------------------------------------------------------------------------
namespace soagen::examples
{
/// @brief entities
///
/// @details
///
/// @remark Models the <a href="https://en.wikipedia.org/wiki/AoS_and_SoA">Structure-of-arrays</a>
/// equivalent of: @code{.cpp}
/// struct entities
/// {
/// unsigned id;
/// std::string name;
/// vec3 pos;
/// quaternion orient;
/// };
/// @endcode
///
///
/// @note The code and documentation for this class were generated by soagen - https://marzer.github.io/soagen
class SOAGEN_EMPTY_BASES entities //
SOAGEN_HIDDEN_BASE(public soagen::mixins::size_and_capacity<entities>,
public soagen::mixins::resizable<entities>,
public soagen::mixins::equality_comparable<entities>,
public soagen::mixins::less_than_comparable<entities>,
public soagen::mixins::data_ptr<entities>,
public soagen::mixins::columns<entities>,
public soagen::mixins::rows<entities>,
public soagen::mixins::iterators<entities>,
public soagen::mixins::spans<entities>,
public soagen::mixins::swappable<entities>)
{
public:
/// @brief The unsigned integer size type used by this class.
using size_type = std::size_t;
/// @brief The signed integer difference type used by this class.
using difference_type = std::ptrdiff_t;
/// @brief The allocator type used by this class.
using allocator_type = soagen::allocator_type<entities>;
/// @brief This class's underlying soagen::table type.
using table_type = soagen::table_type<entities>;
/// @brief The soagen::table_traits for the underlying table.
using table_traits = soagen::table_traits_type<entities>;
/// @brief The number of columns in the table.
static constexpr size_type column_count = table_traits::column_count;
/// @brief Gets the soagen::column_traits for a specific column of the table.
template <auto Column>
using column_traits =
POXY_IMPLEMENTATION_DETAIL(typename table_traits::template column<static_cast<size_type>(Column)>);
/// @brief Gets the type of a specific column in the table.
template <auto Column>
using column_type =
POXY_IMPLEMENTATION_DETAIL(typename column_traits<static_cast<size_type>(Column)>::value_type);
/// @brief Row iterators returned by iterator functions.
using iterator = soagen::iterator_type<entities>;
/// @brief Row iterators returned by rvalue-qualified iterator functions.
using rvalue_iterator = soagen::iterator_type<entities&&>;
/// @brief Row iterators returned by const-qualified iterator functions.
using const_iterator = soagen::const_iterator_type<entities>;
/// @brief Regular (lvalue-qualified) span type.
using span_type = soagen::span_type<entities>;
/// @brief Rvalue-qualified span type.
using rvalue_span_type = soagen::span_type<entities&&>;
/// @brief Const-qualified span type.
using const_span_type = soagen::const_span_type<entities>;
/// @brief Regular (lvalue-qualified) row type used by this class.
using row_type = soagen::row_type<entities>;
/// @brief Rvalue row type used by this class.
using rvalue_row_type = soagen::row_type<entities&&>;
/// @brief Const row type used by this class.
using const_row_type = soagen::const_row_type<entities>;
/// @brief The number of rows to advance to maintain the requested `alignment` for every column.
///
/// @details The stride size you need to use when iterating through rows of this table such that
/// the starting element for each batch in each column would have the same memory alignment as the
/// value specified for the column-specific `alignment`.
///
/// @note Typically you can ignore this; column elements are always aligned correctly according to their
/// type. This is for over-alignment scenarios where you need to do things in batches (e.g. SIMD).
static constexpr size_type aligned_stride = table_traits::aligned_stride;
#if SOAGEN_DOXYGEN
/// @brief Named index constants for all of the columns in the table.
using columns = POXY_IMPLEMENTATION_DETAIL(struct dummy_t);
#else
enum class columns : size_type
{
id = 0,
name = 1,
pos = 2,
orient = 3,
};
#endif
/// @brief Gets the name of the specified column as a null-terminated string.
template <auto Column>
static constexpr auto& column_name =
soagen::detail::column_name<entities, static_cast<size_type>(Column)>::value;
private:
/// @cond
table_type table_;
/// @endcond
public:
/// @brief Default constructor.
SOAGEN_NODISCARD_CTOR
entities() = default;
/// @brief Move constructor.
SOAGEN_NODISCARD_CTOR
entities(entities&&) = default;
/// @brief Move-assignment operator.
entities& operator=(entities&&) = default;
/// @brief Copy constructor.
SOAGEN_NODISCARD_CTOR
entities(const entities&) = default;
/// @brief Copy-assignment operator.
entities& operator=(const entities&) = default;
/// @brief Destructor.
~entities() = default;
/// @brief Constructs with the given allocator.
SOAGEN_NODISCARD_CTOR
constexpr explicit entities(const allocator_type& alloc) noexcept //
: table_{ alloc }
{}
/// @brief Constructs with the given allocator.
SOAGEN_NODISCARD_CTOR
constexpr explicit entities(allocator_type&& alloc) noexcept //
: table_{ static_cast<allocator_type&&>(alloc) }
{}
/// @brief Returns the allocator being used by the table.
SOAGEN_INLINE_GETTER
SOAGEN_CPP20_CONSTEXPR
allocator_type get_allocator() const noexcept
{
return table_.get_allocator();
}
/// @name Underlying table
/// @{
/// @brief Returns an lvalue reference to the underlying soagen::table.
SOAGEN_PURE_INLINE_GETTER
constexpr table_type& table() & noexcept
{
return table_;
}
/// @brief Returns an rvalue reference to the underlying soagen::table.
SOAGEN_PURE_INLINE_GETTER
constexpr table_type&& table() && noexcept
{
return static_cast<table_type&&>(table_);
}
/// @brief Returns a const lvalue reference to the underlying soagen::table.
SOAGEN_PURE_INLINE_GETTER
constexpr const table_type& table() const& noexcept
{
return table_;
}
/// @brief Returns an lvalue reference to the underlying soagen::table.
SOAGEN_PURE_INLINE_GETTER
explicit constexpr operator table_type&() noexcept
{
return table_;
}
/// @brief Returns an rvalue reference to the underlying soagen::table.
SOAGEN_PURE_INLINE_GETTER
explicit constexpr operator table_type&&() noexcept
{
return static_cast<table_type&&>(table_);
}
/// @brief Returns a const lvalue reference to the underlying soagen::table.
SOAGEN_PURE_INLINE_GETTER
explicit constexpr operator const table_type&() const noexcept
{
return table_;
}
/// @}
/// @name Modifiers
/// @{
/// @brief Erases the row at the given position.
///
/// @availability This method is only available when all the column types are move-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = soagen::has_erase_member<table_type>)
SOAGEN_ALWAYS_INLINE
SOAGEN_CPP20_CONSTEXPR //
SOAGEN_ENABLE_IF_T(entities&, sfinae) erase(size_type pos) //
noexcept(soagen::has_nothrow_erase_member<table_type>) //
{
table_.erase(pos);
return *this;
}
/// @brief Erases the row at the given position without preserving order.
///
/// @details This is much faster than #erase() because it uses the swap-and-pop idiom:
/// Instead of shifting all the higher rows downward, the last row is moved into the
/// position of the erased one and the size of the table is reduced by 1.
///
/// @note If you are tracking row indices in some other place and need to maintain that invariant,
/// you can use the return value to update your data accordingly.
///
/// @returns The position of the row that was moved into the erased row's position, if any.
///
/// @availability This method is only available when all the column types are move-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = soagen::has_unordered_erase_member<table_type>)
SOAGEN_ALWAYS_INLINE
SOAGEN_CPP20_CONSTEXPR //
SOAGEN_ENABLE_IF_T(soagen::optional<size_type>, sfinae) unordered_erase(size_type pos) //
noexcept(soagen::has_nothrow_unordered_erase_member<table_type>) //
{
return table_.unordered_erase(pos);
}
/// @brief Erases the row at the given iterator.
///
/// @returns An iterator to the row immediately following the one which was removed,
/// or #end() if the one removed was the last row in the table.
///
/// @availability This method is only available when all the column types are move-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = soagen::has_erase_member<table_type>)
SOAGEN_ALWAYS_INLINE
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(iterator, sfinae) erase(iterator pos) //
noexcept(soagen::has_nothrow_erase_member<table_type>) //
{
table_.erase(static_cast<size_type>(pos));
return pos;
}
/// @brief Erases the row at the given position without preserving order.
///
/// @details This is much faster than #erase() because it uses the swap-and-pop idiom:
/// Instead of shifting all the higher rows downward, the last row is moved into the
/// position of the erased one and the size of the table is reduced by 1.
///
/// @note If you are tracking row indices in some other place and need to maintain that invariant,
/// you can use the return value to update your data accordingly.
///
/// @returns The position of the row that was moved into the erased row's position, if any.
///
/// @availability This method is only available when all the column types are move-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = soagen::has_unordered_erase_member<table_type>)
SOAGEN_ALWAYS_INLINE
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(soagen::optional<iterator>, sfinae) unordered_erase(iterator pos) //
noexcept(soagen::has_nothrow_unordered_erase_member<table_type>) //
{
if (auto moved_pos = table_.unordered_erase(static_cast<size_type>(pos)); moved_pos)
return iterator{ *this, static_cast<difference_type>(*moved_pos) };
return {};
}
/// @brief Erases the row at the given iterator.
///
/// @returns An iterator to the row immediately following the one which was removed,
/// or #cend() if the one removed was the last row in the table.
///
/// @availability This method is only available when all the column types are move-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = soagen::has_erase_member<table_type>)
SOAGEN_ALWAYS_INLINE
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(const_iterator, sfinae) erase(const_iterator pos) //
noexcept(soagen::has_nothrow_erase_member<table_type>) //
{
table_.erase(static_cast<size_type>(pos));
return pos;
}
/// @brief Erases the row at the given position without preserving order.
///
/// @details This is much faster than #erase() because it uses the swap-and-pop idiom:
/// Instead of shifting all the higher rows downward, the last row is moved into the
/// position of the erased one and the size of the table is reduced by 1.
///
/// @note If you are tracking row indices in some other place and need to maintain that invariant,
/// you can use the return value to update your data accordingly.
///
/// @returns The position of the row that was moved into the erased row's position, if any.
///
/// @availability This method is only available when all the column types are move-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = soagen::has_unordered_erase_member<table_type>)
SOAGEN_ALWAYS_INLINE
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(soagen::optional<const_iterator>, sfinae) unordered_erase(const_iterator pos) //
noexcept(soagen::has_nothrow_unordered_erase_member<table_type>) //
{
if (auto moved_pos = table_.unordered_erase(static_cast<size_type>(pos)); moved_pos)
return const_iterator{ *this, static_cast<difference_type>(*moved_pos) };
return {};
}
/// @brief Swaps two columns.
///
/// @availability The two columns must have the same underlying value_type.
template <auto A, auto B>
SOAGEN_ALWAYS_INLINE
SOAGEN_CPP20_CONSTEXPR
entities& swap_columns() //
noexcept(noexcept(std::declval<table_type&>()
.template swap_columns<static_cast<size_type>(A), static_cast<size_type>(B)>()))
{
table_.template swap_columns<static_cast<size_type>(A), static_cast<size_type>(B)>();
return *this;
}
#if SOAGEN_DOXYGEN
/// @brief Removes the last row(s) from the table.
entities& pop_back(size_type num = 1) noexcept(...);
/// @brief Removes all rows from table.
entities& clear() noexcept;
/// @brief Resizes the table to the given number of rows.
///
/// @availability This method is only available when all the column types are default-constructible.
entities& resize(size_type new_size) //
noexcept(soagen::has_nothrow_resize_member<table_type>);
/// @brief Swaps the contents of the table with another.
///
/// @availability This method is only available when #allocator_type is swappable or non-propagating.
constexpr void swap(entities& other) //
noexcept(soagen::has_nothrow_swap_member<table_type>);
#endif
/// @}
/// @name Adding rows
/// @{
// ------ push_back() --------------------------------------------------------------------------
/// @brief Adds a new row at the end of the table.
SOAGEN_CPP20_CONSTEXPR
entities& push_back(column_traits<0>::param_type id,
column_traits<1>::param_type name = "",
column_traits<2>::param_type pos = {},
column_traits<3>::param_type orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::push_back_is_nothrow<table_type>) //
{
table_.emplace_back(static_cast<column_traits<0>::param_forward_type>(id),
static_cast<column_traits<1>::param_forward_type>(name),
static_cast<column_traits<2>::param_forward_type>(pos),
static_cast<column_traits<3>::param_forward_type>(orient));
return *this;
}
/// @brief Adds a new row at the end of the table (rvalue overload).
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = table_traits::rvalues_are_distinct)
SOAGEN_CPP20_CONSTEXPR
entities& push_back(column_traits<0>::rvalue_type id,
column_traits<1>::rvalue_type name = "",
column_traits<2>::rvalue_type pos = {},
column_traits<3>::rvalue_type orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::rvalue_push_back_is_nothrow<table_type>) //
{
table_.emplace_back(static_cast<column_traits<0>::rvalue_forward_type>(id),
static_cast<column_traits<1>::rvalue_forward_type>(name),
static_cast<column_traits<2>::rvalue_forward_type>(pos),
static_cast<column_traits<3>::rvalue_forward_type>(orient));
return *this;
}
// ------ emplace_back() -----------------------------------------------------------------------
/// @brief Constructs a new row directly in-place at the end of the table.
SOAGEN_CONSTRAINED_TEMPLATE((table_traits::row_constructible_from<Id&&, Name&&, Pos&&, Orient&&>), //
typename Id,
typename Name = column_traits<1>::default_emplace_type,
typename Pos = column_traits<2>::default_emplace_type,
typename Orient = column_traits<3>::default_emplace_type) //
SOAGEN_CPP20_CONSTEXPR
entities& emplace_back(Id&& id, Name&& name = "", Pos&& pos = {}, Orient&& orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::emplace_back_is_nothrow<table_type, Id&&, Name&&, Pos&&, Orient&&>) //
{
table_.emplace_back(static_cast<Id&&>(id),
static_cast<Name&&>(name),
static_cast<Pos&&>(pos),
static_cast<Orient&&>(orient));
return *this;
}
/// @brief Constructs a new row directly in-place at the end of the table by unpacking a tuple-like object.
SOAGEN_CONSTRAINED_TEMPLATE(table_traits::row_constructible_from<Tuple>, typename Tuple)
SOAGEN_CPP20_CONSTEXPR
entities& emplace_back(Tuple&& tuple_) //
noexcept(table_traits::emplace_back_is_nothrow<table_type, Tuple&&>) //
{
table_.emplace_back(static_cast<Tuple&&>(tuple_));
return *this;
}
/// @}
/// @name Inserting rows
/// @availability These overloads are only available when all the column types are move/copy-constructible and move/copy-assignable.
/// @{
private:
/// @cond
static constexpr bool can_insert_ =
table_traits::all_move_or_copy_constructible && table_traits::all_move_or_copy_assignable;
static constexpr bool can_insert_rvalues_ = can_insert_ && table_traits::rvalues_are_distinct;
/// @endcond
public:
// ------ insert(size_type) --------------------------------------------------------------------
/// @brief Inserts a new row at an arbitrary position in the table.
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = can_insert_) //
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(entities&, sfinae) insert(size_type index_,
column_traits<0>::param_type id,
column_traits<1>::param_type name = "",
column_traits<2>::param_type pos = {},
column_traits<3>::param_type orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::insert_is_nothrow<table_type>) //
{
table_.emplace(index_,
static_cast<column_traits<0>::param_forward_type>(id),
static_cast<column_traits<1>::param_forward_type>(name),
static_cast<column_traits<2>::param_forward_type>(pos),
static_cast<column_traits<3>::param_forward_type>(orient));
return *this;
}
/// @brief Inserts a new row at an arbitrary position in the table (rvalue overload).
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = can_insert_rvalues_) //
SOAGEN_CPP20_CONSTEXPR
entities& insert(SOAGEN_ENABLE_IF_T(size_type, sfinae) index_,
column_traits<0>::rvalue_type id,
column_traits<1>::rvalue_type name = "",
column_traits<2>::rvalue_type pos = {},
column_traits<3>::rvalue_type orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::insert_is_nothrow<table_type>) //
{
table_.emplace(index_,
static_cast<column_traits<0>::rvalue_forward_type>(id),
static_cast<column_traits<1>::rvalue_forward_type>(name),
static_cast<column_traits<2>::rvalue_forward_type>(pos),
static_cast<column_traits<3>::rvalue_forward_type>(orient));
return *this;
}
// ------ insert(iterator) ---------------------------------------------------------------------
/// @brief Inserts a new row at an arbitrary position in the table.
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = can_insert_) //
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(iterator, sfinae) insert(iterator iter_,
column_traits<0>::param_type id,
column_traits<1>::param_type name = "",
column_traits<2>::param_type pos = {},
column_traits<3>::param_type orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::insert_is_nothrow<table_type>) //
{
table_.emplace(static_cast<size_type>(iter_),
static_cast<column_traits<0>::param_forward_type>(id),
static_cast<column_traits<1>::param_forward_type>(name),
static_cast<column_traits<2>::param_forward_type>(pos),
static_cast<column_traits<3>::param_forward_type>(orient));
return iter_;
}
/// @brief Inserts a new row at an arbitrary position in the table.
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = can_insert_) //
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(const_iterator, sfinae) insert(const_iterator iter_,
column_traits<0>::param_type id,
column_traits<1>::param_type name = "",
column_traits<2>::param_type pos = {},
column_traits<3>::param_type orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::insert_is_nothrow<table_type>) //
{
table_.emplace(static_cast<size_type>(iter_),
static_cast<column_traits<0>::param_forward_type>(id),
static_cast<column_traits<1>::param_forward_type>(name),
static_cast<column_traits<2>::param_forward_type>(pos),
static_cast<column_traits<3>::param_forward_type>(orient));
return iter_;
}
/// @brief Inserts a new row at an arbitrary position in the table (rvalue overload).
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = can_insert_rvalues_) //
SOAGEN_CPP20_CONSTEXPR
iterator insert(SOAGEN_ENABLE_IF_T(iterator, sfinae) iter_,
column_traits<0>::rvalue_type id,
column_traits<1>::rvalue_type name = "",
column_traits<2>::rvalue_type pos = {},
column_traits<3>::rvalue_type orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::insert_is_nothrow<table_type>) //
{
table_.emplace(static_cast<size_type>(iter_),
static_cast<column_traits<0>::rvalue_forward_type>(id),
static_cast<column_traits<1>::rvalue_forward_type>(name),
static_cast<column_traits<2>::rvalue_forward_type>(pos),
static_cast<column_traits<3>::rvalue_forward_type>(orient));
return iter_;
}
/// @brief Inserts a new row at an arbitrary position in the table (rvalue overload).
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_HIDDEN_CONSTRAINT(sfinae, bool sfinae = can_insert_rvalues_) //
SOAGEN_CPP20_CONSTEXPR
const_iterator insert(SOAGEN_ENABLE_IF_T(const_iterator, sfinae) iter_,
column_traits<0>::rvalue_type id,
column_traits<1>::rvalue_type name = "",
column_traits<2>::rvalue_type pos = {},
column_traits<3>::rvalue_type orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::insert_is_nothrow<table_type>) //
{
table_.emplace(static_cast<size_type>(iter_),
static_cast<column_traits<0>::rvalue_forward_type>(id),
static_cast<column_traits<1>::rvalue_forward_type>(name),
static_cast<column_traits<2>::rvalue_forward_type>(pos),
static_cast<column_traits<3>::rvalue_forward_type>(orient));
return iter_;
}
// ------ emplace(size_type) -------------------------------------------------------------------
/// @brief Constructs a new row directly in-place at an arbitrary position in the table.
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_CONSTRAINED_TEMPLATE(
sfinae,
typename Id,
typename Name = column_traits<1>::default_emplace_type,
typename Pos = column_traits<2>::default_emplace_type,
typename Orient = column_traits<3>::default_emplace_type SOAGEN_HIDDEN_PARAM(
bool sfinae = table_traits::row_constructible_from<Id&&, Name&&, Pos&&, Orient&&> && can_insert_)) //
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(entities&, sfinae) emplace(size_type index_,
Id&& id,
Name&& name = "",
Pos&& pos = {},
Orient&& orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::emplace_is_nothrow<table_type, Id&&, Name&&, Pos&&, Orient&&>) //
{
table_.emplace(index_,
static_cast<Id&&>(id),
static_cast<Name&&>(name),
static_cast<Pos&&>(pos),
static_cast<Orient&&>(orient));
return *this;
}
/// @brief Constructs a new row directly in-place at an arbitrary position in the table by unpacking a tuple-like object.
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_CONSTRAINED_TEMPLATE(sfinae,
typename Tuple SOAGEN_HIDDEN_PARAM(
bool sfinae = table_traits::row_constructible_from<Tuple&&> && can_insert_)) //
SOAGEN_CPP20_CONSTEXPR
entities& emplace(SOAGEN_ENABLE_IF_T(size_type, sfinae) index_, Tuple&& tuple_) //
noexcept(table_traits::emplace_is_nothrow<table_type, Tuple&&>) //
{
table_.emplace(index_, static_cast<Tuple&&>(tuple_));
return *this;
}
// ------ emplace(iterator) --------------------------------------------------------------------
/// @brief Constructs a new row directly in-place at an arbitrary position in the table.
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_CONSTRAINED_TEMPLATE(
sfinae,
typename Id,
typename Name = column_traits<1>::default_emplace_type,
typename Pos = column_traits<2>::default_emplace_type,
typename Orient = column_traits<3>::default_emplace_type SOAGEN_HIDDEN_PARAM(
bool sfinae = table_traits::row_constructible_from<Id&&, Name&&, Pos&&, Orient&&> && can_insert_)) //
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(iterator, sfinae) emplace(iterator iter_,
Id&& id,
Name&& name = "",
Pos&& pos = {},
Orient&& orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::emplace_is_nothrow<table_type, Id&&, Name&&, Pos&&, Orient&&>) //
{
table_.emplace(static_cast<size_type>(iter_),
static_cast<Id&&>(id),
static_cast<Name&&>(name),
static_cast<Pos&&>(pos),
static_cast<Orient&&>(orient));
return iter_;
}
/// @brief Constructs a new row directly in-place at an arbitrary position in the table by unpacking a tuple-like object.
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_CONSTRAINED_TEMPLATE(sfinae,
typename Tuple SOAGEN_HIDDEN_PARAM(
bool sfinae = table_traits::row_constructible_from<Tuple&&> && can_insert_)) //
SOAGEN_CPP20_CONSTEXPR
iterator emplace(SOAGEN_ENABLE_IF_T(iterator, sfinae) iter_, Tuple&& tuple_) //
noexcept(table_traits::emplace_is_nothrow<table_type, Tuple&&>) //
{
table_.emplace(static_cast<size_type>(iter_), static_cast<Tuple&&>(tuple_));
return iter_;
}
/// @brief Constructs a new row directly in-place at an arbitrary position in the table.
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_CONSTRAINED_TEMPLATE(
sfinae,
typename Id,
typename Name = column_traits<1>::default_emplace_type,
typename Pos = column_traits<2>::default_emplace_type,
typename Orient = column_traits<3>::default_emplace_type SOAGEN_HIDDEN_PARAM(
bool sfinae = table_traits::row_constructible_from<Id&&, Name&&, Pos&&, Orient&&> && can_insert_)) //
SOAGEN_CPP20_CONSTEXPR
SOAGEN_ENABLE_IF_T(const_iterator, sfinae) emplace(const_iterator iter_,
Id&& id,
Name&& name = "",
Pos&& pos = {},
Orient&& orient = { 1, 0, 0, 0 }) //
noexcept(table_traits::emplace_is_nothrow<table_type, Id&&, Name&&, Pos&&, Orient&&>) //
{
table_.emplace(static_cast<size_type>(iter_),
static_cast<Id&&>(id),
static_cast<Name&&>(name),
static_cast<Pos&&>(pos),
static_cast<Orient&&>(orient));
return iter_;
}
/// @brief Constructs a new row directly in-place at an arbitrary position in the table by unpacking a tuple-like object.
///
/// @availability This overload is only available when all the column types are move/copy-constructible and move/copy-assignable.
SOAGEN_CONSTRAINED_TEMPLATE(sfinae,
typename Tuple SOAGEN_HIDDEN_PARAM(
bool sfinae = table_traits::row_constructible_from<Tuple&&> && can_insert_)) //
SOAGEN_CPP20_CONSTEXPR
const_iterator emplace(SOAGEN_ENABLE_IF_T(const_iterator, sfinae) iter_, Tuple&& tuple_) //
noexcept(table_traits::emplace_is_nothrow<table_type, Tuple&&>) //
{
table_.emplace(static_cast<size_type>(iter_), static_cast<Tuple&&>(tuple_));
return iter_;
}
/// @}
/// @name Columns
/// @{
/// @brief Returns a pointer to the elements of a specific column.
template <auto Column>
SOAGEN_COLUMN(entities, Column)
constexpr column_type<Column>* column() noexcept
{
static_assert(static_cast<size_type>(Column) < table_traits::column_count, "column index out of range");
return soagen::assume_aligned<soagen::actual_alignment<entities, Column>>(table_.template column<Column>());
}
/// @brief Returns a pointer to the elements of a specific column.
template <auto Column>
SOAGEN_COLUMN(entities, Column)
constexpr std::add_const_t<column_type<Column>>* column() const noexcept
{
static_assert(static_cast<size_type>(Column) < table_traits::column_count, "column index out of range");
return soagen::assume_aligned<soagen::actual_alignment<entities, Column>>(table_.template column<Column>());
}
#if SOAGEN_DOXYGEN
/// @brief Returns a pointer to the raw byte backing array.
///
/// @availability This method is only available when all the column types are trivially-copyable.
constexpr std::byte* data() noexcept;
/// @brief Returns a pointer to the raw byte backing array.
///
/// @availability This method is only available when all the column types are trivially-copyable.
constexpr const std::byte* const data() noexcept;
/// @brief Returns a pointer to the elements in column [0]: id.
constexpr unsigned* id() noexcept;
/// @brief Returns a pointer to the elements in column [0]: id.
constexpr const unsigned* id() const noexcept;
/// @brief Returns a pointer to the elements in column [1]: name.
constexpr std::string* name() noexcept;
/// @brief Returns a pointer to the elements in column [1]: name.
constexpr const std::string* name() const noexcept;
/// @brief Returns a pointer to the elements in column [2]: pos.
constexpr vec3* pos() noexcept;
/// @brief Returns a pointer to the elements in column [2]: pos.
constexpr const vec3* pos() const noexcept;
/// @brief Returns a pointer to the elements in column [3]: orient.
constexpr quaternion* orient() noexcept;
/// @brief Returns a pointer to the elements in column [3]: orient.
constexpr const quaternion* orient() const noexcept;
/// @brief Invokes a function once for each column data pointer.
///
/// @tparam Func A callable type compatible with one of the following signatures:<ul>
/// <li> `void(auto*, std::integral_constant<size_type, N>)`
/// <li> `void(auto*, size_type)`
/// <li> `void(std::integral_constant<size_type, N>, auto*)`
/// <li> `void(size_type, auto*)`
/// <li> `void(auto*)`
/// </ul>
/// Overload resolution is performed in the order listed above.
///
/// @param func The callable to invoke.
template <typename Func>
constexpr void for_each_column(Func&& func) noexcept(...);
/// @brief Invokes a function once for each column data pointer.
///
/// @tparam Func A callable type compatible with one of the following signatures:<ul>
/// <li> `void(auto*, std::integral_constant<size_type, N>)`
/// <li> `void(auto*, size_type)`
/// <li> `void(std::integral_constant<size_type, N>, auto*)`
/// <li> `void(size_type, auto*)`
/// <li> `void(auto*)`
/// </ul>
/// Overload resolution is performed in the order listed above.
///
/// @param func The callable to invoke.
template <typename Func>
constexpr void for_each_column(Func&& func) const noexcept(...);
#endif
/// @}
#if SOAGEN_DOXYGEN
/// @name Capacity
/// @{
/// @brief Returns true if the number of rows is zero.
SOAGEN_PURE_INLINE_GETTER
constexpr bool empty() const noexcept;
/// @brief Returns the current number of rows.
SOAGEN_PURE_INLINE_GETTER
constexpr size_type size() const noexcept;