4#ifndef TETL_ARRAY_ARRAY_HPP
5#define TETL_ARRAY_ARRAY_HPP
7#include <etl/_config/all.hpp>
9#include <etl/_algorithm/equal.hpp>
10#include <etl/_algorithm/fill_n.hpp>
11#include <etl/_algorithm/lexicographical_compare.hpp>
12#include <etl/_algorithm/swap_ranges.hpp>
13#include <etl/_array/c_array.hpp>
14#include <etl/_contracts/check.hpp>
15#include <etl/_cstddef/size_t.hpp>
16#include <etl/_iterator/begin.hpp>
17#include <etl/_iterator/data.hpp>
18#include <etl/_iterator/end.hpp>
19#include <etl/_iterator/prev.hpp>
20#include <etl/_iterator/rbegin.hpp>
21#include <etl/_iterator/rend.hpp>
22#include <etl/_iterator/reverse_iterator.hpp>
23#include <etl/_iterator/size.hpp>
24#include <etl/_tuple/is_tuple_like.hpp>
25#include <etl/_tuple/tuple_element.hpp>
26#include <etl/_tuple/tuple_size.hpp>
27#include <etl/_type_traits/conditional.hpp>
28#include <etl/_type_traits/is_nothrow_swappable.hpp>
29#include <etl/_type_traits/remove_cv.hpp>
30#include <etl/_utility/index_sequence.hpp>
31#include <etl/_utility/move.hpp>
32#include <etl/_utility/unreachable.hpp>
48template <
typename Type, size_t Size>
50 using value_type = Type;
51 using size_type = size_t;
52 using difference_type = ptrdiff_t;
53 using pointer = Type*;
54 using const_pointer = Type
const*;
55 using reference = Type&;
56 using const_reference = Type
const&;
57 using iterator = Type*;
58 using const_iterator = Type
const*;
59 using reverse_iterator =
typename etl::reverse_iterator<iterator>;
60 using const_reverse_iterator =
typename etl::reverse_iterator<const_iterator>;
65 if constexpr (Size == 0) {
68 TETL_PRECONDITION_SAFE(pos < Size);
69 return _internal_array_do_not_use_directly[pos];
74 [[
nodiscard]]
constexpr auto operator[](size_type
const pos)
const noexcept -> const_reference
76 if constexpr (Size == 0) {
79 TETL_PRECONDITION_SAFE(pos < Size);
80 return _internal_array_do_not_use_directly[pos];
99 return *
etl::prev(end());
105 return *
etl::prev(end());
129 if constexpr (Size == 0) {
132 return etl::begin(_internal_array_do_not_use_directly);
139 if constexpr (Size == 0) {
142 return etl::begin(_internal_array_do_not_use_directly);
155 if constexpr (Size == 0) {
158 return etl::end(_internal_array_do_not_use_directly);
165 if constexpr (Size == 0) {
168 return etl::end(_internal_array_do_not_use_directly);
183 return reverse_iterator(end());
191 return const_reverse_iterator(end());
208 return reverse_iterator(begin());
215 [[
nodiscard]]
constexpr auto rend()
const noexcept -> const_reverse_iterator
217 return const_reverse_iterator(begin());
232 return begin() == end();
253 constexpr auto fill(const_reference value) ->
void
255 etl::fill_n(begin(), Size, value);
263 etl::swap_ranges(begin(), end(), other.begin());
277 return etl::equal(lhs.begin(), lhs.end(), rhs.begin());
284 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
303 using array_t = conditional_t<Size == 0,
empty_c_array, c_array<Type, Size + size_t{Size == 0}>>;
314template <
typename T,
typename... U>
320template <
typename T, size_t N>
329template <size_t I,
typename T>
332template <size_t I,
typename T, size_t N>
333struct tuple_element<I,
array<T, N>> {
341template <size_t Index,
typename T, size_t Size>
342[[nodiscard]]
constexpr auto get(
array<T, Size>& array)
noexcept -> T&
344 static_assert(Index < Size,
"array index out of range");
349template <size_t Index,
typename T, size_t Size>
350[[nodiscard]]
constexpr auto get(
array<T, Size>
const& array)
noexcept -> T
const&
352 static_assert(Index < Size,
"array index out of range");
357template <size_t Index,
typename T, size_t Size>
358[[nodiscard]]
constexpr auto get(
array<T, Size>&& array)
noexcept -> T&&
360 static_assert(Index < Size,
"array index out of range");
361 return etl::move(array[Index]);
365template <size_t Index,
typename T, size_t Size>
366[[nodiscard]]
constexpr auto get(
array<T, Size>
const&& array)
noexcept -> T
const&&
368 static_assert(Index < Size,
"array index out of range");
369 return etl::move(array[Index]);
376template <
typename T, size_t N>
379 return [&]<etl::size_t... I>(
etl::index_sequence<I...> ) {
380 return etl::
array<
etl::remove_cv_t<T>, N>{{a[I]...}};
381 }(
etl::make_index_sequence<N>{});
385template <
typename T, size_t N>
388 return [&]<etl::size_t... I>(
etl::index_sequence<I...> ) {
390 }(
etl::make_index_sequence<N>{});
Definition adjacent_find.hpp:9
constexpr auto is_etl_array< array< T, Size > >
Definition array.hpp:397
constexpr auto is_etl_array
Definition array.hpp:394
auto unreachable() -> void
Definition unreachable.hpp:11
A container that encapsulates fixed size arrays.
Definition array.hpp:49
constexpr auto fill(const_reference value) -> void
Assigns the given value value to all elements in the container.
Definition array.hpp:253
constexpr auto to_array(T(&&a)[N])
Definition array.hpp:386
constexpr auto front() const noexcept -> const_reference
Accesses the first item.
Definition array.hpp:91
constexpr auto get(array< T, Size > &&array) noexcept -> T &&
Definition array.hpp:358
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first element of the reversed array. It corresponds to the last ele...
Definition array.hpp:197
array(T, U...) -> array< T, 1+sizeof...(U)>
One deduction guide is provided for array to provide an equivalent of experimental::make_array for co...
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first element of the reversed array. It corresponds to the last ele...
Definition array.hpp:189
constexpr auto get(array< T, Size > const &&array) noexcept -> T const &&
Definition array.hpp:366
constexpr auto is_tuple_like
Definition array.hpp:325
friend constexpr auto operator<(array const &lhs, array const &rhs) -> bool
Compares the contents of lhs and rhs lexicographically. The comparison is performed by a function equ...
Definition array.hpp:282
constexpr auto operator[](size_type const pos) noexcept -> reference
Accesses the specified item with range checking.
Definition array.hpp:63
constexpr auto operator[](size_type const pos) const noexcept -> const_reference
Accesses the specified item with range checking.
Definition array.hpp:74
constexpr auto back() noexcept -> reference
Accesses the last item.
Definition array.hpp:97
constexpr auto rend() noexcept -> reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed array....
Definition array.hpp:206
constexpr auto get(array< T, Size > &array) noexcept -> T &
Extracts the Ith element element from the array. I must be an integer value in range [0,...
Definition array.hpp:342
constexpr auto begin() noexcept -> iterator
Returns an iterator to the beginning.
Definition array.hpp:127
constexpr auto end() noexcept -> iterator
Returns an iterator to the end.
Definition array.hpp:153
constexpr auto begin() const noexcept -> const_iterator
Returns an iterator to the beginning.
Definition array.hpp:137
constexpr auto cbegin() const noexcept -> const_iterator
Returns an const iterator to the beginning.
Definition array.hpp:147
friend constexpr auto operator==(array const &lhs, array const &rhs) -> bool
Checks if the contents of lhs and rhs are equal, that is, they have the same number of elements and e...
Definition array.hpp:275
constexpr auto empty() const noexcept -> bool
Checks if the container has no elements, i.e. whether begin() == end().
Definition array.hpp:230
constexpr auto data() noexcept -> pointer
Returns pointer to the underlying array serving as element storage. The pointer is such that range [d...
Definition array.hpp:112
constexpr auto back() const noexcept -> const_reference
Accesses the last item.
Definition array.hpp:103
constexpr auto front() noexcept -> reference
Accesses the first item.
Definition array.hpp:85
friend constexpr auto operator>(array const &lhs, array const &rhs) -> bool
Definition array.hpp:292
friend constexpr auto swap(array &lhs, array &rhs) noexcept(noexcept(lhs.swap(rhs))) -> void
Specializes the swap algorithm for array. Swaps the contents of lhs and rhs.
Definition array.hpp:267
constexpr auto to_array(T(&a)[N]) -> array< remove_cv_t< T >, N >
Creates a array from the one dimensional built-in array a. The elements of the array are copy-initial...
Definition array.hpp:377
constexpr auto get(array< T, Size > const &array) noexcept -> T const &
Definition array.hpp:350
constexpr auto max_size() const noexcept -> size_type
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition array.hpp:247
constexpr auto end() const noexcept -> const_iterator
Returns an iterator to the end.
Definition array.hpp:163
constexpr auto crend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed array....
Definition array.hpp:224
friend constexpr auto operator>=(array const &lhs, array const &rhs) -> bool
Definition array.hpp:297
friend constexpr auto operator<=(array const &lhs, array const &rhs) -> bool
Definition array.hpp:287
constexpr auto swap(array &other) noexcept(is_nothrow_swappable_v< Type >) -> void
Exchanges the contents of the container with those of other. Does not cause iterators and references ...
Definition array.hpp:261
constexpr auto data() const noexcept -> const_pointer
Returns pointer to the underlying array serving as element storage. The pointer is such that range [d...
Definition array.hpp:121
constexpr auto rend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed array....
Definition array.hpp:215
constexpr auto size() const noexcept -> size_type
Returns the number of elements in the container, i.e. distance(begin(), end()).
Definition array.hpp:236
constexpr auto cend() const noexcept -> const_iterator
Returns an const iterator to the end.
Definition array.hpp:173
constexpr auto rbegin() noexcept -> reverse_iterator
Returns a reverse iterator to the first element of the reversed array. It corresponds to the last ele...
Definition array.hpp:181
Definition c_array.hpp:16
Definition integral_constant.hpp:10