28 using difference_type = sarr_soa_detail::difference_type;
29 using size_type = sarr_soa_detail::size_type;
40 sarr_soa_iterator(uint8_t* ptr, uint32_t cnt, uint32_t idx): m_ptr(ptr), m_cnt(cnt), m_idx(idx) {}
45 T operator->()
const {
48 iterator operator[](size_type offset)
const {
49 return iterator(m_ptr, m_cnt, m_idx + offset);
52 iterator& operator+=(size_type diff) {
56 iterator& operator-=(size_type diff) {
79 iterator operator+(size_type offset)
const {
80 return iterator(m_ptr, m_cnt, m_idx + offset);
82 iterator operator-(size_type offset)
const {
83 return iterator(m_ptr, m_cnt, m_idx + offset);
85 difference_type operator-(
const iterator& other)
const {
86 GAIA_ASSERT(m_ptr == other.m_ptr);
87 return (difference_type)(m_idx - other.m_idx);
90 GAIA_NODISCARD
bool operator==(
const iterator& other)
const {
91 GAIA_ASSERT(m_ptr == other.m_ptr);
92 return m_idx == other.m_idx;
94 GAIA_NODISCARD
bool operator!=(
const iterator& other)
const {
95 GAIA_ASSERT(m_ptr == other.m_ptr);
96 return m_idx != other.m_idx;
98 GAIA_NODISCARD
bool operator>(
const iterator& other)
const {
99 GAIA_ASSERT(m_ptr == other.m_ptr);
100 return m_idx > other.m_idx;
102 GAIA_NODISCARD
bool operator>=(
const iterator& other)
const {
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;
118 using value_type = T;
121 using difference_type = sarr_soa_detail::difference_type;
122 using size_type = sarr_soa_detail::size_type;
128 const uint8_t* m_ptr;
135 T operator*()
const {
138 T operator->()
const {
141 iterator operator[](size_type offset)
const {
142 return iterator(m_ptr, m_cnt, m_idx + offset);
145 iterator& operator+=(size_type diff) {
149 iterator& operator-=(size_type diff) {
172 iterator operator+(size_type offset)
const {
173 return iterator(m_ptr, m_cnt, m_idx + offset);
175 iterator operator-(size_type offset)
const {
176 return iterator(m_ptr, m_cnt, m_idx + offset);
178 difference_type operator-(
const iterator& other)
const {
179 GAIA_ASSERT(m_ptr == other.m_ptr);
180 return (difference_type)(m_idx - other.m_idx);
183 GAIA_NODISCARD
bool operator==(
const iterator& other)
const {
184 GAIA_ASSERT(m_ptr == other.m_ptr);
185 return m_idx == other.m_idx;
187 GAIA_NODISCARD
bool operator!=(
const iterator& other)
const {
188 GAIA_ASSERT(m_ptr == other.m_ptr);
189 return m_idx != other.m_idx;
191 GAIA_NODISCARD
bool operator>(
const iterator& other)
const {
192 GAIA_ASSERT(m_ptr == other.m_ptr);
193 return m_idx > other.m_idx;
195 GAIA_NODISCARD
bool operator>=(
const iterator& other)
const {
196 GAIA_ASSERT(m_ptr == other.m_ptr);
197 return m_idx >= other.m_idx;
199 GAIA_NODISCARD
bool operator<(
const iterator& other)
const {
200 GAIA_ASSERT(m_ptr == other.m_ptr);
201 return m_idx < other.m_idx;
203 GAIA_NODISCARD
bool operator<=(
const iterator& other)
const {
204 GAIA_ASSERT(m_ptr == other.m_ptr);
205 return m_idx <= other.m_idx;
213 static_assert(mem::is_soa_layout_v<T>,
"sarr_soa can be used only with soa types");
216 static_assert(N > 0);
218 using value_type = T;
219 using reference = T&;
220 using const_reference =
const T&;
222 using const_pointer = T*;
224 using difference_type = sarr_soa_detail::difference_type;
225 using size_type = sarr_soa_detail::size_type;
231 static constexpr size_type extent = N;
232 static constexpr uint32_t allocated_bytes = view_policy::get_min_byte_size(0, N);
236 constexpr sarr_soa()
noexcept =
default;
242 for (
auto i = (size_type)0; i < extent; ++i)
248 template <
typename InputIt>
249 constexpr sarr_soa(InputIt first, InputIt last)
noexcept {
250 const auto count = (size_type)core::distance(first, last);
252 if constexpr (std::is_pointer_v<InputIt>) {
253 for (size_type i = 0; i < count; ++i)
254 operator[](i) = first[i];
255 }
else if constexpr (std::is_same_v<typename InputIt::iterator_category, core::random_access_iterator_tag>) {
256 for (size_type i = 0; i < count; ++i)
257 operator[](i) = *(first[i]);
260 for (
auto it = first; it != last; ++it)
261 operator[](++i) = *it;
265 constexpr sarr_soa(std::initializer_list<T> il): sarr_soa(il.begin(), il.end()) {}
267 constexpr sarr_soa(
const sarr_soa& other): sarr_soa(other.begin(), other.end()) {}
269 constexpr sarr_soa(sarr_soa&& other)
noexcept {
270 GAIA_ASSERT(core::addressof(other) !=
this);
272 mem::move_elements<T, true>((uint8_t*)m_data, (uint8_t*)other.m_data, other.size(), 0, extent, other.extent);
275 sarr_soa& operator=(std::initializer_list<T> il) {
276 *
this = sarr_soa(il.begin(), il.end());
280 constexpr sarr_soa& operator=(
const sarr_soa& other) {
281 GAIA_ASSERT(core::addressof(other) !=
this);
283 mem::copy_elements<T, true>(
284 GAIA_ACC((uint8_t*)&m_data[0]), GAIA_ACC((
const uint8_t*)&other.m_data[0]), other.size(), 0, extent,
290 constexpr sarr_soa& operator=(sarr_soa&& other)
noexcept {
291 GAIA_ASSERT(core::addressof(other) !=
this);
293 mem::move_elements<T, true>(
294 GAIA_ACC((uint8_t*)&m_data[0]), GAIA_ACC((uint8_t*)&other.m_data[0]), other.size(), 0, extent,
300 GAIA_CLANG_WARNING_PUSH()
302 GAIA_CLANG_WARNING_DISABLE("-Wcast-align")
304 GAIA_NODISCARD constexpr pointer data() noexcept {
305 return GAIA_ACC((pointer)&m_data[0]);
308 GAIA_NODISCARD
constexpr const_pointer data() const noexcept {
309 return GAIA_ACC((const_pointer)&m_data[0]);
312 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](size_type pos)
noexcept {
313 GAIA_ASSERT(pos < size());
314 return view_policy::set({GAIA_ACC((
typename view_policy::TargetCastType) & m_data[0]), extent}, pos);
317 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](size_type pos)
const noexcept {
318 GAIA_ASSERT(pos < size());
319 return view_policy::get({GAIA_ACC((
typename view_policy::TargetCastType) & m_data[0]), extent}, pos);
322 GAIA_CLANG_WARNING_POP()
324 GAIA_NODISCARD constexpr size_type size() const noexcept {
328 GAIA_NODISCARD
constexpr bool empty() const noexcept {
329 return begin() == end();
332 GAIA_NODISCARD
constexpr size_type capacity() const noexcept {
336 GAIA_NODISCARD
constexpr size_type max_size() const noexcept {
340 GAIA_NODISCARD
constexpr decltype(
auto) front() noexcept {
344 GAIA_NODISCARD
constexpr decltype(
auto) front() const noexcept {
348 GAIA_NODISCARD
constexpr decltype(
auto) back() noexcept {
349 return (
operator[])(N - 1);
352 GAIA_NODISCARD
constexpr decltype(
auto) back() const noexcept {
353 return operator[](N - 1);
356 GAIA_NODISCARD
constexpr auto begin() noexcept {
357 return iterator(GAIA_ACC(&m_data[0]), extent, 0);
360 GAIA_NODISCARD
constexpr auto begin() const noexcept {
361 return const_iterator(GAIA_ACC(&m_data[0]), extent, 0);
364 GAIA_NODISCARD
constexpr auto cbegin() const noexcept {
365 return const_iterator(GAIA_ACC(&m_data[0]), extent, 0);
368 GAIA_NODISCARD
constexpr auto rbegin() noexcept {
369 return iterator(GAIA_ACC(&m_data[0]), extent, size() - 1);
372 GAIA_NODISCARD
constexpr auto rbegin() const noexcept {
373 return const_iterator(m_data, extent, size() - 1);
376 GAIA_NODISCARD
constexpr auto crbegin() const noexcept {
377 return const_iterator(m_data, extent, size() - 1);
380 GAIA_NODISCARD
constexpr auto end() noexcept {
381 return iterator(GAIA_ACC(&m_data[0]), extent, size());
384 GAIA_NODISCARD
constexpr auto end() const noexcept {
385 return const_iterator(GAIA_ACC(&m_data[0]), extent, size());
388 GAIA_NODISCARD
constexpr auto cend() const noexcept {
389 return const_iterator(GAIA_ACC(&m_data[0]), extent, size());
392 GAIA_NODISCARD
constexpr auto rend() noexcept {
393 return iterator(GAIA_ACC(&m_data[0]), extent, -1);
396 GAIA_NODISCARD
constexpr auto rend() const noexcept {
397 return const_iterator(GAIA_ACC(&m_data[0]), extent, -1);
400 GAIA_NODISCARD
constexpr auto crend() const noexcept {
401 return const_iterator(GAIA_ACC(&m_data[0]), extent, -1);
404 GAIA_NODISCARD
constexpr bool operator==(
const sarr_soa& other)
const {
405 for (size_type i = 0; i < N; ++i)
406 if (!(
operator[](i) == other[i]))
411 GAIA_NODISCARD
constexpr bool operator!=(
const sarr_soa& other)
const {
412 return !operator==(other);
415 template <
size_t Item>
416 auto view_mut() noexcept {
417 return mem::data_view_policy<T::gaia_Data_Layout, T>::template set<Item>(
421 template <
size_t Item>
422 auto view() const noexcept {
423 return mem::data_view_policy<T::gaia_Data_Layout, T>::template get<Item>(