32 using const_reference =
const T&;
34 using const_pointer =
const T*;
36 using difference_type = sarr_detail::difference_type;
37 using size_type = sarr_detail::size_type;
39 using iterator = pointer;
40 using const_iterator = const_pointer;
43 static constexpr size_t value_size =
sizeof(T);
44 static constexpr size_type extent = N;
45 static constexpr uint32_t allocated_bytes = view_policy::get_min_byte_size(0, N);
49 constexpr sarr()
noexcept {
50 core::call_ctor_raw_n(data(), extent);
56 core::call_ctor_raw_n(data(), extent);
59 for (
auto i = (size_type)0; i < extent; ++i)
64 core::call_dtor_n(data(), extent);
67 template <
typename InputIt>
68 constexpr sarr(InputIt first, InputIt last)
noexcept {
69 core::call_ctor_raw_n(data(), extent);
71 const auto count = (size_type)core::distance(first, last);
73 if constexpr (std::is_pointer_v<InputIt>) {
74 for (size_type i = 0; i < count; ++i)
75 operator[](i) = first[i];
76 }
else if constexpr (std::is_same_v<typename InputIt::iterator_category, core::random_access_iterator_tag>) {
77 for (size_type i = 0; i < count; ++i)
78 operator[](i) = *(first[i]);
81 for (
auto it = first; it != last; ++it)
82 operator[](++i) = *it;
86 constexpr sarr(std::initializer_list<T> il): sarr(il.begin(), il.end()) {}
88 constexpr sarr(
const sarr& other): sarr(other.begin(), other.end()) {}
90 constexpr sarr(sarr&& other)
noexcept {
91 GAIA_ASSERT(core::addressof(other) !=
this);
93 core::call_ctor_raw_n(data(), extent);
94 mem::move_elements<T, false>((uint8_t*)m_data, (uint8_t*)other.m_data, other.size(), 0, extent, other.extent);
97 sarr& operator=(std::initializer_list<T> il) {
98 *
this = sarr(il.begin(), il.end());
102 constexpr sarr& operator=(
const sarr& other) {
103 GAIA_ASSERT(core::addressof(other) !=
this);
105 core::call_ctor_raw_n(data(), extent);
106 mem::copy_elements<T, false>(
107 GAIA_ACC((uint8_t*)&m_data[0]), GAIA_ACC((
const uint8_t*)&other.m_data[0]), other.size(), 0, extent,
113 constexpr sarr& operator=(sarr&& other)
noexcept {
114 GAIA_ASSERT(core::addressof(other) !=
this);
116 core::call_ctor_raw_n(data(), extent);
117 mem::move_elements<T, false>(
118 GAIA_ACC((uint8_t*)&m_data[0]), GAIA_ACC((uint8_t*)&other.m_data[0]), other.size(), 0, extent,
124 GAIA_CLANG_WARNING_PUSH()
126 GAIA_CLANG_WARNING_DISABLE("-Wcast-align")
128 GAIA_NODISCARD constexpr pointer data() noexcept {
129 return GAIA_ACC((pointer)&m_data[0]);
132 GAIA_NODISCARD
constexpr const_pointer data() const noexcept {
133 return GAIA_ACC((const_pointer)&m_data[0]);
136 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](size_type pos)
noexcept {
137 GAIA_ASSERT(pos < size());
138 return view_policy::set({GAIA_ACC((
typename view_policy::TargetCastType) & m_data[0]), extent}, pos);
141 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](size_type pos)
const noexcept {
142 GAIA_ASSERT(pos < size());
143 return view_policy::get({GAIA_ACC((
typename view_policy::TargetCastType) & m_data[0]), extent}, pos);
146 GAIA_CLANG_WARNING_POP()
148 GAIA_NODISCARD constexpr size_type size() const noexcept {
152 GAIA_NODISCARD
constexpr bool empty() const noexcept {
153 return begin() == end();
156 GAIA_NODISCARD
constexpr size_type capacity() const noexcept {
160 GAIA_NODISCARD
constexpr size_type max_size() const noexcept {
164 GAIA_NODISCARD
constexpr decltype(
auto) front() noexcept {
165 return (reference)*begin();
168 GAIA_NODISCARD
constexpr decltype(
auto) front() const noexcept {
169 return (const_reference)*begin();
172 GAIA_NODISCARD
constexpr decltype(
auto) back() noexcept {
173 return (reference) operator[](N - 1);
176 GAIA_NODISCARD
constexpr decltype(
auto) back() const noexcept {
177 return (const_reference) operator[](N - 1);
180 GAIA_NODISCARD
constexpr auto begin() noexcept {
181 return iterator(GAIA_ACC(&m_data[0]));
184 GAIA_NODISCARD
constexpr auto begin() const noexcept {
185 return const_iterator(GAIA_ACC(&m_data[0]));
188 GAIA_NODISCARD
constexpr auto cbegin() const noexcept {
189 return const_iterator(GAIA_ACC(&m_data[0]));
192 GAIA_NODISCARD
constexpr auto rbegin() noexcept {
193 return iterator((pointer)&back());
196 GAIA_NODISCARD
constexpr auto rbegin() const noexcept {
197 return const_iterator((const_pointer)&back());
200 GAIA_NODISCARD
constexpr auto crbegin() const noexcept {
201 return const_iterator((const_pointer)&back());
204 GAIA_NODISCARD
constexpr auto end() noexcept {
205 return iterator(GAIA_ACC((pointer)&m_data[0]) + size());
208 GAIA_NODISCARD
constexpr auto end() const noexcept {
209 return const_iterator(GAIA_ACC((const_pointer)&m_data[0]) + size());
212 GAIA_NODISCARD
constexpr auto cend() const noexcept {
213 return const_iterator(GAIA_ACC((const_pointer)&m_data[0]) + size());
216 GAIA_NODISCARD
constexpr auto rend() noexcept {
217 return iterator(GAIA_ACC((pointer)&m_data[0]) - 1);
220 GAIA_NODISCARD
constexpr auto rend() const noexcept {
221 return const_iterator(GAIA_ACC((const_pointer)&m_data[0]) - 1);
224 GAIA_NODISCARD
constexpr auto crend() const noexcept {
225 return const_iterator(GAIA_ACC((const_pointer)&m_data[0]) - 1);
228 GAIA_NODISCARD
constexpr bool operator==(
const sarr& other)
const {
229 for (size_type i = 0; i < N; ++i)
230 if (!(
operator[](i) == other[i]))
235 GAIA_NODISCARD
constexpr bool operator!=(
const sarr& other)
const {
236 return !operator==(other);