2#include "gaia/config/config.h"
5#include <initializer_list>
11#include "gaia/core/iterator.h"
12#include "gaia/core/utility.h"
13#include "gaia/mem/data_layout_policy.h"
14#include "gaia/mem/mem_utils.h"
15#include "gaia/mem/raw_data_holder.h"
20 namespace sarr_ext_detail {
28 template <
typename T, sarr_ext_detail::
size_type N>
65 mem::raw_data_holder<T, allocated_bytes> m_data;
74 core::call_dtor_n(
data(), m_cnt);
94 template <
typename InputIt>
96 const auto count = (
size_type)core::distance(first, last);
99 if constexpr (std::is_pointer_v<InputIt>) {
101 operator[](
i) = first[
i];
102 }
else if constexpr (std::is_same_v<typename InputIt::iterator_category, core::random_access_iterator_tag>) {
104 operator[](
i) = *(first[
i]);
107 for (
auto it = first;
it != last; ++
it)
108 operator[](++
i) = *
it;
123 GAIA_ASSERT(core::addressof(other) !=
this);
126 mem::move_elements<T, false>(m_data, other.m_data, other.size(), 0,
extent, other.extent);
143 GAIA_ASSERT(core::addressof(other) !=
this);
146 mem::copy_elements<T, false>(
157 GAIA_ASSERT(core::addressof(other) !=
this);
160 mem::move_elements<T, false>(
169 GAIA_CLANG_WARNING_PUSH()
171 GAIA_CLANG_WARNING_DISABLE("-
Wcast-align")
176 return GAIA_ACC((
pointer)&m_data[0]);
188 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](
size_type pos)
noexcept {
196 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](
size_type pos)
const noexcept {
201 GAIA_CLANG_WARNING_POP()
206 GAIA_ASSERT(
size() <
N);
208 auto* ptr = &
data()[m_cnt++];
209 core::call_ctor(ptr,
arg);
215 GAIA_ASSERT(
size() <
N);
217 auto* ptr = &
data()[m_cnt++];
218 core::call_ctor(ptr, GAIA_MOV(
arg));
225 template <
typename...
Args>
227 GAIA_ASSERT(
size() <
N);
229 auto* ptr = &
data()[m_cnt++];
230 core::call_ctor(ptr, GAIA_FWD(
args)...);
236 GAIA_ASSERT(!
empty());
238 auto* ptr = &
data()[m_cnt - 1];
239 core::call_dtor(ptr);
249 GAIA_ASSERT(
size() <
N);
259 core::call_ctor(ptr,
arg);
271 GAIA_ASSERT(
size() <
N);
281 core::call_ctor(ptr, GAIA_MOV(
arg));
303 auto* ptr = &
data()[m_cnt - 1];
304 core::call_dtor(ptr);
316 GAIA_ASSERT(first >=
data())
318 GAIA_ASSERT(last > first);
319 GAIA_ASSERT(last <= (
data() +
size()));
326 const auto cnt = (
size_type)(last - first);
330 core::call_dtor_n(&
data()[m_cnt - cnt], cnt);
347 auto* ptr = &
data()[m_cnt - 1];
348 core::call_dtor(ptr);
366 if (count <= m_cnt) {
368 core::call_dtor_n(&
data()[count],
size() - count);
386 if constexpr (std::is_copy_constructible_v<value_type>) {
392 operator[](
i) = value;
400 template <
typename Func>
407 if (func(
operator[](
idxSrc))) {
412 core::call_dtor(
ptr2);
417 core::call_dtor(ptr);
455 GAIA_ASSERT(!
empty());
462 GAIA_ASSERT(!
empty());
469 GAIA_ASSERT(!
empty());
476 GAIA_ASSERT(!
empty());
556 if (m_cnt != other.m_cnt)
560 if (!(
operator[](
i) == other[
i]))
575 template <
typename T, uint32_t N, uint32_t... I>
576 constexpr sarr_ext<std::remove_cv_t<T>, N> to_sarray_impl(T (&a)[N], std::index_sequence<I...> ) {
587 template <
typename T, u
int32_t N>
588 constexpr sarr_ext<std::remove_cv_t<T>, N> to_sarray(T (&a)[N]) {
589 return detail::to_sarray_impl(a, std::make_index_sequence<N>{});
598 template <
typename T, u
int32_t N>
599 struct tuple_size<gaia::cnt::sarr_ext<T, N>>: std::integral_constant<uint32_t, N> {};
601 template <
size_t I,
typename T, u
int32_t N>
602 struct tuple_element<I, gaia::cnt::sarr_ext<T, N>> {
Array with variable size of elements of type.
Definition darray_impl.h:27
darr_detail::size_type size_type
Unsigned type used for sizes and indices.
Definition darray_impl.h:44
GAIA_NODISCARD auto begin() noexcept
Returns an iterator to the first element.
Definition darray_impl.h:556
darr_detail::difference_type difference_type
Type used for iterator differences.
Definition darray_impl.h:42
GAIA_NODISCARD auto end() noexcept
Returns an iterator one past the last element.
Definition darray_impl.h:592
Array of elements of type.
Definition sarray_ext_impl.h:29
constexpr sarr_ext(size_type count) noexcept
Constructs a container with the requested number of value-initialized elements.
Definition sarray_ext_impl.h:86
GAIA_NODISCARD constexpr decltype(auto) back() noexcept
Accesses the last element.
Definition sarray_ext_impl.h:468
GAIA_NODISCARD constexpr bool operator!=(const sarr_ext &other) const noexcept
Checks whether two containers differ.
Definition sarray_ext_impl.h:568
GAIA_NODISCARD constexpr auto cbegin() const noexcept
Returns a read-only iterator to the first element.
Definition sarray_ext_impl.h:494
constexpr void clear() noexcept
Removes all elements.
Definition sarray_ext_impl.h:356
constexpr void push_back(const T &arg) noexcept
Appends an element.
Definition sarray_ext_impl.h:205
sarr_ext & operator=(std::initializer_list< T > il)
Replaces the elements from an initializer list.
Definition sarray_ext_impl.h:134
pointer iterator
Mutable random-access iterator type.
Definition sarray_ext_impl.h:51
constexpr iterator erase(iterator pos) noexcept
Removes the element at pos.
Definition sarray_ext_impl.h:291
T * pointer
Mutable element pointer type.
Definition sarray_ext_impl.h:40
constexpr sarr_ext & operator=(sarr_ext &&other) noexcept
Move-assigns the container.
Definition sarray_ext_impl.h:156
GAIA_NODISCARD constexpr auto crend() const noexcept
Returns the read-only reverse traversal sentinel preceding the first element.
Definition sarray_ext_impl.h:548
constexpr sarr_ext(InputIt first, InputIt last) noexcept
Constructs a container from an iterator range.
Definition sarray_ext_impl.h:95
sarr_ext_detail::difference_type difference_type
Type used for iterator differences.
Definition sarray_ext_impl.h:46
GAIA_NODISCARD constexpr const_pointer data() const noexcept
Returns a pointer to the element storage.
Definition sarray_ext_impl.h:181
GAIA_NODISCARD constexpr auto begin() const noexcept
Returns an iterator to the first element.
Definition sarray_ext_impl.h:488
iterator insert(iterator pos, const T &arg) noexcept
Insert the element to the position given by iterator pos.
Definition sarray_ext_impl.h:248
static constexpr size_t value_size
Size of one element in bytes.
Definition sarray_ext_impl.h:58
constexpr sarr_ext(std::initializer_list< T > il)
Constructs a container from an initializer list.
Definition sarray_ext_impl.h:114
constexpr void pop_back() noexcept
Removes the last element.
Definition sarray_ext_impl.h:235
GAIA_NODISCARD constexpr auto begin() noexcept
Returns an iterator to the first element.
Definition sarray_ext_impl.h:482
const T * const_pointer
Read-only element pointer type.
Definition sarray_ext_impl.h:42
GAIA_NODISCARD constexpr auto rend() const noexcept
Returns the reverse traversal sentinel preceding the first element.
Definition sarray_ext_impl.h:542
constexpr void push_back(T &&arg) noexcept
Appends an element.
Definition sarray_ext_impl.h:214
iterator erase_at(size_type pos) noexcept
Definition sarray_ext_impl.h:339
GAIA_NODISCARD constexpr auto end() noexcept
Returns an iterator one past the last element.
Definition sarray_ext_impl.h:518
GAIA_NODISCARD constexpr size_type capacity() const noexcept
Returns the number of elements that fit without reallocation.
Definition sarray_ext_impl.h:442
GAIA_NODISCARD constexpr bool empty() const noexcept
Checks whether the container has no elements.
Definition sarray_ext_impl.h:436
constexpr void resize(size_type count, const_reference value) noexcept
Changes the size and initializes new elements from a value.
Definition sarray_ext_impl.h:382
GAIA_NODISCARD constexpr decltype(auto) operator[](size_type pos) noexcept
Accesses an element without bounds checking in optimized builds.
Definition sarray_ext_impl.h:188
auto retain(Func &&func) noexcept
Removes all elements that fail the predicate.
Definition sarray_ext_impl.h:401
GAIA_NODISCARD constexpr auto crbegin() const noexcept
Returns a read-only reverse traversal iterator to the last element.
Definition sarray_ext_impl.h:512
GAIA_NODISCARD constexpr pointer data() noexcept
Returns a pointer to the element storage.
Definition sarray_ext_impl.h:175
constexpr sarr_ext(sarr_ext &&other) noexcept
Move-constructs a container.
Definition sarray_ext_impl.h:122
constexpr sarr_ext & operator=(const sarr_ext &other)
Copy-assigns the container.
Definition sarray_ext_impl.h:142
GAIA_NODISCARD constexpr auto end() const noexcept
Returns an iterator one past the last element.
Definition sarray_ext_impl.h:524
GAIA_NODISCARD constexpr bool operator==(const sarr_ext &other) const noexcept
Compares two containers element by element.
Definition sarray_ext_impl.h:555
iterator insert(iterator pos, T &&arg) noexcept
Insert the element to the position given by iterator pos.
Definition sarray_ext_impl.h:270
static constexpr size_type extent
Fixed capacity of the container.
Definition sarray_ext_impl.h:60
GAIA_NODISCARD constexpr auto rbegin() noexcept
Returns a reverse traversal iterator to the last element.
Definition sarray_ext_impl.h:500
GAIA_NODISCARD constexpr auto cend() const noexcept
Returns a read-only iterator one past the last element.
Definition sarray_ext_impl.h:530
constexpr void resize(size_type count) noexcept
Changes the number of elements.
Definition sarray_ext_impl.h:362
GAIA_NODISCARD constexpr size_type max_size() const noexcept
Returns the maximum number of elements supported by this container.
Definition sarray_ext_impl.h:448
const_pointer const_iterator
Read-only random-access iterator type.
Definition sarray_ext_impl.h:53
GAIA_NODISCARD constexpr decltype(auto) back() const noexcept
Accesses the last element.
Definition sarray_ext_impl.h:475
iterator erase(iterator first, iterator last) noexcept
Removes the elements in the range [first, last)
Definition sarray_ext_impl.h:315
GAIA_NODISCARD constexpr decltype(auto) front() const noexcept
Accesses the first element.
Definition sarray_ext_impl.h:461
GAIA_NODISCARD constexpr size_type size() const noexcept
Returns the number of elements.
Definition sarray_ext_impl.h:430
GAIA_NODISCARD constexpr auto rbegin() const noexcept
Returns a reverse traversal iterator to the last element.
Definition sarray_ext_impl.h:506
GAIA_NODISCARD constexpr decltype(auto) front() noexcept
Accesses the first element.
Definition sarray_ext_impl.h:454
constexpr sarr_ext(const sarr_ext &other)
Copy-constructs a container.
Definition sarray_ext_impl.h:118
static constexpr uint32_t allocated_bytes
Number of bytes reserved by the inline storage.
Definition sarray_ext_impl.h:62
sarr_ext_detail::size_type size_type
Unsigned type used for sizes and indices.
Definition sarray_ext_impl.h:48
constexpr sarr_ext(size_type count, const_reference value) noexcept
Constructs a container with copies of a value.
Definition sarray_ext_impl.h:80
GAIA_NODISCARD constexpr auto rend() noexcept
Returns the reverse traversal sentinel preceding the first element.
Definition sarray_ext_impl.h:536
constexpr decltype(auto) emplace_back(Args &&... args) noexcept
Constructs and appends an element.
Definition sarray_ext_impl.h:226
View policy for accessing and storing data in the AoS way. Good for random access and when accessing ...
Definition data_layout_policy.h:162
static GAIA_NODISCARD constexpr uint32_t get_min_byte_size(uintptr_t addr, size_t cnt) noexcept
Calculates the bytes required for a value range.
Definition data_layout_policy.h:175
std::add_pointer_t< ValueType > TargetCastType
Pointer type used to address stored values.
Definition data_layout_policy.h:164
GAIA_NODISCARD static constexpr ValueType & set(std::span< ValueType > s, size_t idx) noexcept
Returns a mutable value reference from an AoS span.
Definition data_layout_policy.h:238
GAIA_NODISCARD static constexpr const ValueType & get(std::span< const ValueType > s, size_t idx) noexcept
Returns a read-only value reference from an AoS span.
Definition data_layout_policy.h:230