2#include "gaia/config/config.h"
5#include <initializer_list>
11#include "gaia/cnt/impl/array_utils.h"
12#include "gaia/core/iterator.h"
13#include "gaia/core/utility.h"
14#include "gaia/mem/data_layout_policy.h"
15#include "gaia/mem/mem_utils.h"
16#include "gaia/mem/raw_data_holder.h"
21 namespace sarr_ext_soa_detail {
29 struct sarr_ext_soa_iterator {
36 using size_type = sarr_ext_soa_detail::size_type;
38 using iterator = sarr_ext_soa_iterator;
48 sarr_ext_soa_iterator(uint8_t* ptr,
size_type cnt,
size_type idx): m_ptr(ptr), m_cnt(cnt), m_idx(idx) {}
51 return mem::data_view_policy<T::gaia_Data_Layout, T>::get({m_ptr, m_cnt}, m_idx);
53 T operator->()
const {
54 return mem::data_view_policy<T::gaia_Data_Layout, T>::get({m_ptr, m_cnt}, m_idx);
94 GAIA_ASSERT(m_ptr == other.m_ptr);
99 GAIA_ASSERT(m_ptr == other.m_ptr);
100 return m_idx == other.m_idx;
103 GAIA_ASSERT(m_ptr == other.m_ptr);
104 return m_idx != other.m_idx;
106 GAIA_NODISCARD
bool operator>(
const iterator& other)
const {
107 GAIA_ASSERT(m_ptr == other.m_ptr);
108 return m_idx > other.m_idx;
110 GAIA_NODISCARD
bool operator>=(
const iterator& other)
const {
111 GAIA_ASSERT(m_ptr == other.m_ptr);
112 return m_idx >= other.m_idx;
114 GAIA_NODISCARD
bool operator<(
const iterator& other)
const {
115 GAIA_ASSERT(m_ptr == other.m_ptr);
116 return m_idx < other.m_idx;
118 GAIA_NODISCARD
bool operator<=(
const iterator& other)
const {
119 GAIA_ASSERT(m_ptr == other.m_ptr);
120 return m_idx <= other.m_idx;
124 template <
typename T>
125 struct const_sarr_ext_soa_iterator {
130 using size_type = sarr_ext_soa_detail::size_type;
132 using iterator = const_sarr_ext_soa_iterator;
136 const uint8_t* m_ptr;
142 m_ptr(ptr), m_cnt(cnt), m_idx(idx) {}
144 T operator*()
const {
145 return mem::data_view_policy<T::gaia_Data_Layout, T>::get({m_ptr, m_cnt}, m_idx);
147 T operator->()
const {
148 return mem::data_view_policy<T::gaia_Data_Layout, T>::get({m_ptr, m_cnt}, m_idx);
188 GAIA_ASSERT(m_ptr == other.m_ptr);
193 GAIA_ASSERT(m_ptr == other.m_ptr);
194 return m_idx == other.m_idx;
197 GAIA_ASSERT(m_ptr == other.m_ptr);
198 return m_idx != other.m_idx;
200 GAIA_NODISCARD
bool operator>(
const iterator& other)
const {
201 GAIA_ASSERT(m_ptr == other.m_ptr);
202 return m_idx > other.m_idx;
204 GAIA_NODISCARD
bool operator>=(
const iterator& other)
const {
205 GAIA_ASSERT(m_ptr == other.m_ptr);
206 return m_idx >= other.m_idx;
208 GAIA_NODISCARD
bool operator<(
const iterator& other)
const {
209 GAIA_ASSERT(m_ptr == other.m_ptr);
210 return m_idx < other.m_idx;
212 GAIA_NODISCARD
bool operator<=(
const iterator& other)
const {
213 GAIA_ASSERT(m_ptr == other.m_ptr);
214 return m_idx <= other.m_idx;
221 template <
typename T, sarr_ext_soa_detail::
size_type N>
223 static_assert(mem::is_soa_layout_v<T>,
"sarr_ext_soa can be used only with soa types");
226 static_assert(
N > 0);
262 mem::raw_data_holder<T, allocated_bytes> m_data;
289 template <
typename InputIt>
291 const auto count = (
size_type)core::distance(first, last);
294 if constexpr (std::is_pointer_v<InputIt>) {
296 operator[](
i) = first[
i];
297 }
else if constexpr (std::is_same_v<typename InputIt::iterator_category, core::random_access_iterator_tag>) {
299 operator[](
i) = *(first[
i]);
302 for (
auto it = first;
it != last; ++
it)
303 operator[](
i++) = *
it;
318 GAIA_ASSERT(core::addressof(
other) !=
this);
337 GAIA_ASSERT(core::addressof(
other) !=
this);
340 mem::copy_elements<T, true>(
351 GAIA_ASSERT(core::addressof(
other) !=
this);
354 mem::move_elements<T, true>(
363 GAIA_CLANG_WARNING_PUSH()
365 GAIA_CLANG_WARNING_DISABLE("-
Wcast-align")
370 return GAIA_ACC((
pointer)&m_data[0]);
382 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](
size_type pos)
noexcept {
390 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](
size_type pos)
const noexcept {
395 GAIA_CLANG_WARNING_POP()
400 GAIA_ASSERT(
size() <
N);
408 GAIA_ASSERT(
size() <
N);
417 template <
typename...
Args>
419 GAIA_ASSERT(
size() <
N);
426 GAIA_ASSERT(!
empty());
436 GAIA_ASSERT(
size() <
N);
438 GAIA_ASSERT(
pos <=
end());
456 GAIA_ASSERT(
size() <
N);
458 GAIA_ASSERT(
pos <=
end());
496 GAIA_ASSERT(last > first);
497 GAIA_ASSERT(last <=
end());
504 const auto cnt = (
size_type)(last - first);
548 if constexpr (std::is_copy_constructible_v<value_type>) {
554 operator[](
i) = value;
563 template <
typename Func>
565 return detail::retain_array<true>(*
this, m_cnt, func);
595 GAIA_ASSERT(!
empty());
602 GAIA_ASSERT(!
empty());
609 GAIA_ASSERT(!
empty());
610 return (
operator[])(m_cnt - 1);
616 GAIA_ASSERT(!
empty());
696 if (m_cnt !=
other.m_cnt)
700 if (!(
operator[](
i) ==
other[
i]))
715 template <
size_t Item>
724 template <
size_t Item>
727 std::span<const uint8_t>{GAIA_ACC((
const uint8_t*)&m_data[0]),
extent});
733 template <
typename T, uint32_t N, uint32_t... I>
734 constexpr sarr_ext_soa<std::remove_cv_t<T>, N> to_sarray_impl(T (&a)[N], std::index_sequence<I...> ) {
745 template <
typename T, u
int32_t N>
746 constexpr sarr_ext_soa<std::remove_cv_t<T>, N> to_sarray(T (&a)[N]) {
747 return detail::to_sarray_impl(a, std::make_index_sequence<N>{});
756 template <
typename T, u
int32_t N>
757 struct tuple_size<gaia::cnt::sarr_ext_soa<T, N>>: std::integral_constant<uint32_t, N> {};
759 template <
size_t I,
typename T, u
int32_t N>
760 struct tuple_element<I, gaia::cnt::sarr_ext_soa<T, N>> {
Array of elements of type.
Definition darray_ext_impl.h:31
GAIA_NODISCARD size_type size() const noexcept
Returns the number of elements.
Definition darray_ext_impl.h:561
pointer iterator
Mutable random-access iterator type.
Definition darray_ext_impl.h:53
GAIA_NODISCARD auto begin() noexcept
Returns an iterator to the first element.
Definition darray_ext_impl.h:613
GAIA_NODISCARD auto end() noexcept
Returns an iterator one past the last element.
Definition darray_ext_impl.h:649
GAIA_NODISCARD constexpr bool operator!=(const darr_ext &other) const noexcept
Checks whether two containers differ.
Definition darray_ext_impl.h:699
darr_ext_detail::size_type size_type
Unsigned type used for sizes and indices.
Definition darray_ext_impl.h:50
core::random_access_iterator_tag iterator_category
Iterator category exposed by the container.
Definition darray_ext_impl.h:61
static constexpr size_type extent
Fixed capacity of the container.
Definition darray_ext_impl.h:66
darr_ext_detail::difference_type difference_type
Type used for iterator differences.
Definition darray_ext_impl.h:48
T value_type
Element type stored by the container.
Definition darray_ext_impl.h:36
GAIA_NODISCARD decltype(auto) operator[](size_type pos) noexcept
Accesses an element without bounds checking in optimized builds.
Definition darray_ext_impl.h:249
GAIA_NODISCARD bool operator==(const darr_ext &other) const noexcept
Compares two containers element by element.
Definition darray_ext_impl.h:686
Array of elements of type.
Definition sarray_ext_soa_impl.h:222
sarr_ext_soa_detail::difference_type difference_type
Type used for iterator differences.
Definition sarray_ext_soa_impl.h:241
constexpr void resize(size_type count) noexcept
Changes the number of elements.
Definition sarray_ext_soa_impl.h:535
iterator insert(iterator pos, const T &arg) noexcept
Insert the element to the position given by iterator pos.
Definition sarray_ext_soa_impl.h:435
auto view() const noexcept
Returns a read-only view of one structure-of-arrays member.
Definition sarray_ext_soa_impl.h:725
sarr_ext_soa_detail::size_type size_type
Unsigned type used for sizes and indices.
Definition sarray_ext_soa_impl.h:243
iterator erase(iterator first, iterator last) noexcept
Removes the elements in the range [first, last)
Definition sarray_ext_soa_impl.h:494
GAIA_NODISCARD constexpr bool empty() const noexcept
Checks whether the container has no elements.
Definition sarray_ext_soa_impl.h:576
iterator erase_at(size_type pos) noexcept
Definition sarray_ext_soa_impl.h:515
sarr_ext_soa_iterator< T > iterator
Mutable random-access iterator type.
Definition sarray_ext_soa_impl.h:246
GAIA_NODISCARD constexpr auto end() noexcept
Returns an iterator one past the last element.
Definition sarray_ext_soa_impl.h:658
GAIA_NODISCARD constexpr auto begin() const noexcept
Returns an iterator to the first element.
Definition sarray_ext_soa_impl.h:628
constexpr sarr_ext_soa(std::initializer_list< T > il)
Constructs a container from an initializer list.
Definition sarray_ext_soa_impl.h:309
GAIA_NODISCARD constexpr auto crend() const noexcept
Returns the read-only reverse traversal sentinel preceding the first element.
Definition sarray_ext_soa_impl.h:688
constexpr sarr_ext_soa(sarr_ext_soa &&other) noexcept
Move-constructs a container.
Definition sarray_ext_soa_impl.h:317
auto view_mut() noexcept
Returns a mutable view of one structure-of-arrays member.
Definition sarray_ext_soa_impl.h:716
GAIA_NODISCARD constexpr auto cbegin() const noexcept
Returns a read-only iterator to the first element.
Definition sarray_ext_soa_impl.h:634
GAIA_NODISCARD constexpr decltype(auto) front() const noexcept
Accesses the first element.
Definition sarray_ext_soa_impl.h:601
static constexpr size_type extent
Fixed capacity of the container.
Definition sarray_ext_soa_impl.h:257
static constexpr uint32_t allocated_bytes
Number of bytes reserved by the inline storage.
Definition sarray_ext_soa_impl.h:259
constexpr void push_back(T &&arg) noexcept
Appends an element.
Definition sarray_ext_soa_impl.h:407
const_sarr_ext_soa_iterator< T > const_iterator
Read-only random-access iterator type.
Definition sarray_ext_soa_impl.h:248
GAIA_NODISCARD constexpr decltype(auto) front() noexcept
Accesses the first element.
Definition sarray_ext_soa_impl.h:594
constexpr iterator erase(iterator pos) noexcept
Removes the element at pos.
Definition sarray_ext_soa_impl.h:474
GAIA_NODISCARD constexpr bool operator!=(const sarr_ext_soa &other) const noexcept
Checks whether two containers differ.
Definition sarray_ext_soa_impl.h:708
GAIA_NODISCARD constexpr auto rbegin() noexcept
Returns a reverse traversal iterator to the last element.
Definition sarray_ext_soa_impl.h:640
auto retain(Func &&func) noexcept
Removes all elements that fail the predicate. The predicate may modify its element but must not chang...
Definition sarray_ext_soa_impl.h:564
constexpr void clear() noexcept
Removes all elements.
Definition sarray_ext_soa_impl.h:529
GAIA_NODISCARD constexpr decltype(auto) back() const noexcept
Accesses the last element.
Definition sarray_ext_soa_impl.h:615
core::reverse_iterator< const_iterator, difference_type > const_reverse_iterator
Read-only reverse random-access iterator type.
Definition sarray_ext_soa_impl.h:252
GAIA_NODISCARD constexpr size_type max_size() const noexcept
Returns the maximum number of elements supported by this container.
Definition sarray_ext_soa_impl.h:588
GAIA_NODISCARD constexpr decltype(auto) back() noexcept
Accesses the last element.
Definition sarray_ext_soa_impl.h:608
constexpr decltype(auto) emplace_back(Args &&... args) noexcept
Constructs and appends an element.
Definition sarray_ext_soa_impl.h:418
GAIA_NODISCARD constexpr auto rend() noexcept
Returns the reverse traversal sentinel preceding the first element.
Definition sarray_ext_soa_impl.h:676
GAIA_NODISCARD constexpr auto cend() const noexcept
Returns a read-only iterator one past the last element.
Definition sarray_ext_soa_impl.h:670
core::reverse_iterator< iterator, difference_type > reverse_iterator
Mutable reverse random-access iterator type.
Definition sarray_ext_soa_impl.h:250
constexpr sarr_ext_soa(InputIt first, InputIt last) noexcept
Constructs a container from an iterator range.
Definition sarray_ext_soa_impl.h:290
GAIA_NODISCARD constexpr size_type size() const noexcept
Returns the number of elements.
Definition sarray_ext_soa_impl.h:570
GAIA_NODISCARD constexpr auto crbegin() const noexcept
Returns a read-only reverse traversal iterator to the last element.
Definition sarray_ext_soa_impl.h:652
GAIA_NODISCARD constexpr const_pointer data() const noexcept
Returns a pointer to the element storage.
Definition sarray_ext_soa_impl.h:375
constexpr void pop_back() noexcept
Removes the last element.
Definition sarray_ext_soa_impl.h:425
GAIA_NODISCARD constexpr decltype(auto) operator[](size_type pos) noexcept
Accesses an element without bounds checking in optimized builds.
Definition sarray_ext_soa_impl.h:382
GAIA_NODISCARD constexpr auto begin() noexcept
Returns an iterator to the first element.
Definition sarray_ext_soa_impl.h:622
constexpr sarr_ext_soa(size_type count, const_reference value) noexcept
Constructs a container with copies of a value.
Definition sarray_ext_soa_impl.h:275
GAIA_NODISCARD constexpr auto end() const noexcept
Returns an iterator one past the last element.
Definition sarray_ext_soa_impl.h:664
GAIA_NODISCARD constexpr auto rend() const noexcept
Returns the reverse traversal sentinel preceding the first element.
Definition sarray_ext_soa_impl.h:682
constexpr sarr_ext_soa & operator=(const sarr_ext_soa &other)
Copy-assigns the container.
Definition sarray_ext_soa_impl.h:336
constexpr sarr_ext_soa & operator=(sarr_ext_soa &&other) noexcept
Move-assigns the container.
Definition sarray_ext_soa_impl.h:350
constexpr void resize(size_type count, const_reference value) noexcept
Changes the size and initializes new elements from a value.
Definition sarray_ext_soa_impl.h:544
GAIA_NODISCARD constexpr auto rbegin() const noexcept
Returns a reverse traversal iterator to the last element.
Definition sarray_ext_soa_impl.h:646
GAIA_NODISCARD constexpr pointer data() noexcept
Returns a pointer to the element storage.
Definition sarray_ext_soa_impl.h:369
constexpr sarr_ext_soa(const sarr_ext_soa &other)
Copy-constructs a container.
Definition sarray_ext_soa_impl.h:313
sarr_ext_soa & operator=(std::initializer_list< T > il)
Replaces the elements from an initializer list.
Definition sarray_ext_soa_impl.h:328
iterator insert(iterator pos, T &&arg) noexcept
Insert the element to the position given by iterator pos.
Definition sarray_ext_soa_impl.h:455
GAIA_NODISCARD constexpr size_type capacity() const noexcept
Returns the number of elements that fit without reallocation.
Definition sarray_ext_soa_impl.h:582
constexpr sarr_ext_soa(size_type count) noexcept
Constructs a container with the requested number of value-initialized elements.
Definition sarray_ext_soa_impl.h:281
constexpr void push_back(const T &arg) noexcept
Appends an element.
Definition sarray_ext_soa_impl.h:399
GAIA_NODISCARD constexpr bool operator==(const sarr_ext_soa &other) const noexcept
Compares two containers element by element.
Definition sarray_ext_soa_impl.h:695
Random-access iterator that traverses an underlying iterator in reverse. The stored iterator denotes ...
Definition iterator.h:24
View policy for accessing and storing data in the SoA way. Good for SIMD processing.
Definition data_layout_policy.h:398
GAIA_NODISCARD static constexpr ValueType get(std::span< const uint8_t > s, size_t idx) noexcept
Reconstructs a value from its SoA fields.
Definition data_layout_policy.h:526
uint8_t * TargetCastType
Pointer type used to address SoA storage.
Definition data_layout_policy.h:404
GAIA_NODISCARD static constexpr uint32_t get_min_byte_size(uintptr_t addr, size_t cnt) noexcept
Calculates the bytes required for an SoA value range.
Definition data_layout_policy.h:427
GAIA_NODISCARD static constexpr auto set(std::span< uint8_t > s, size_t idx) noexcept
Returns a mutable proxy for one complete value.
Definition data_layout_policy.h:578
Storage policy for a selected layout and item type.
Definition data_layout_policy.h:121