5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ARRAY_ARRAY_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ARRAY_ARRAY_HPP_
20#include "arene/base/detail/exceptions.hpp"
21#include "arene/base/detail/wrapped_iterator.hpp"
23#include "arene/base/stdlib_choice/cstddef.hpp"
24#include "arene/base/stdlib_choice/enable_if.hpp"
25#include "arene/base/stdlib_choice/integral_constant.hpp"
26#include "arene/base/stdlib_choice/is_copy_assignable.hpp"
27#include "arene/base/stdlib_choice/is_same.hpp"
28#include "arene/base/stdlib_choice/move.hpp"
29#include "arene/base/stdlib_choice/numeric_limits.hpp"
30#include "arene/base/stdlib_choice/tuple_element.hpp"
31#include "arene/base/stdlib_choice/tuple_size.hpp"
43template <
typename T, std::
size_t N>
47namespace array_detail {
50class array_iter_passkey {
53 explicit array_iter_passkey() noexcept = default;
54 template <typename T, std::
size_t N>
55 friend class ::arene::base::array;
76template <typename T, std::
size_t N>
81 N <= std::numeric_limits<std::ptrdiff_t>::max(),
82 "Array size must be less than the maximum value of std::ptrdiff_t."
105 using iterator = detail::wrapped_iterator<pointer, array_detail::array_iter_passkey>;
107 using const_iterator = detail::wrapped_iterator<const_pointer, array_detail::array_iter_passkey>;
149 constexpr auto data() const noexcept -> T const* {
return values_; }
246 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
249 if (index >=
size()) {
250 array_detail::throw_out_of_range();
262 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
265 if (index >=
size()) {
266 array_detail::throw_out_of_range();
274 constexpr auto front() noexcept -> T& {
return (*
this)[0]; }
279 constexpr auto front() const noexcept -> T const& {
return (*
this)[0]; }
284 constexpr auto back() noexcept -> T& {
return (*
this)[N - 1U]; }
289 constexpr auto back() const noexcept -> T const& {
return (*
this)[N - 1U]; }
302 template <
typename U = T, constra
ints<std::enable_if_t<is_equality_comparable_v<U>>> =
nullptr>
304 return arene::base::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
310 template <std::
size_t UN,
typename U = T, constra
ints<std::enable_if_t<is_equality_comparable_v<U>>> =
nullptr>
373 template <std::
size_t UN,
typename U = T>
375 return !(lhs == rhs);
394 template <std::
size_t UN,
typename U = T, constra
ints<std::enable_if_t<compare_three_way_supported_v<U>>> =
nullptr>
397 return lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
399 template <
typename U = T, constra
ints<std::enable_if_t<compare_three_way_supported_v<U>>> =
nullptr>
403 return arene::base::strong_ordering::greater;
418 template <std::
size_t UN,
typename U = T, constra
ints<std::enable_if_t<has_fast_inequality_check_v<U>>> =
nullptr>
421 if (
size() != rhs.size()) {
444 template <std::
size_t UN>
448 template <std::
size_t UN>
452 template <std::
size_t UN>
456 template <std::
size_t UN>
493 for (
auto& lhs_elem : *
this) {
512 friend constexpr void swap(
array& lhs,
array& rhs)
noexcept(
noexcept(lhs.swap(rhs))) {
533template <
typename T, std::
size_t N>
536template <
typename T, std::
size_t N>
539template <
typename T, std::
size_t N>
565 using iterator = detail::wrapped_iterator<pointer, array_detail::array_iter_passkey>;
567 using const_iterator = detail::wrapped_iterator<const_pointer, array_detail::array_iter_passkey>;
600 constexpr auto data() noexcept -> T* {
return nullptr; }
606 constexpr auto data() const noexcept -> T const* {
return nullptr; }
711 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
714 array_detail::throw_out_of_range();
728 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
731 array_detail::throw_out_of_range();
805 static constexpr void fill(T
const&)
noexcept {}
829 template <std::
size_t UN>
836 template <std::
size_t UN>
840 template <std::
size_t UN>
842 return !(lhs == rhs);
844 template <std::
size_t UN>
848 template <std::
size_t UN>
852 template <std::
size_t UN>
856 template <std::
size_t UN>
884template <std::
size_t I,
typename T, std::
size_t N, constra
ints<std::enable_if_t<(I < N)>> =
nullptr>
885constexpr auto get(array<T, N>& arr) noexcept -> T& {
895template <std::
size_t I,
typename T, std::
size_t N, constra
ints<std::enable_if_t<(I < N)>> =
nullptr>
896constexpr auto get(array<T, N> const& arr) noexcept -> T
const& {
906template <std::
size_t I,
typename T, std::
size_t N, constra
ints<std::enable_if_t<(I < N)>> =
nullptr>
907constexpr auto get(array<T, N>&& arr) noexcept -> T&& {
917template <std::
size_t I,
typename T, std::
size_t N, constra
ints<std::enable_if_t<(I < N)>> =
nullptr>
918constexpr auto get(array<T, N> const&& arr) noexcept -> T
const&& {
936template <
typename T, std::
size_t N>
943template <std::
size_t N,
typename T, std::
size_t ArrN>
945 static_assert(N < ArrN,
"Index out of bounds in std::tuple_element<arene::base::array>");
static constexpr auto crend() noexcept -> const_reverse_iterator
Get a const_reverse_iterator that references one before the first element of the array.
Definition array.hpp:673
ARENE_NORETURN constexpr auto operator[](std::size_t) const noexcept -> T const &
Get a reference to the index'th element of the array.
Definition array.hpp:689
constexpr auto rend() const noexcept -> const_reverse_iterator
Get a const_reverse_iterator that references one before the first element of the array.
Definition array.hpp:656
static constexpr auto cend() noexcept -> const_iterator
Get a const_iterator that references one past the last element of the array.
Definition array.hpp:665
ARENE_NORETURN constexpr auto front() noexcept -> T &
Get a const-reference to the first element of the array.
Definition array.hpp:745
constexpr auto begin() const noexcept -> const_iterator
Get a const_iterator that references the first element of the array.
Definition array.hpp:625
friend constexpr auto operator<(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Compares two arrays lexicographically. Compares the left and right operands.
Definition array.hpp:845
ARENE_NORETURN constexpr auto operator[](std::size_t) noexcept -> T &
Get a reference to the index'th element of the array.
Definition array.hpp:685
constexpr void swap(array &) noexcept
Swap all the elements with another array. This is a noop for an empty array.
Definition array.hpp:811
static constexpr auto cbegin() noexcept -> const_iterator
Get a const_iterator that references the first element of the array.
Definition array.hpp:661
static constexpr auto three_way_compare(array const &, array< T, UN > const &) noexcept -> arene::base::strong_ordering
Compares two arrays lexicographically. Compares the left and right operands.
Definition array.hpp:830
constexpr auto rend() noexcept -> reverse_iterator
Get an reverse_iterator that references one-before the first element of the array.
Definition array.hpp:644
T * pointer
The type of a pointer to an array element.
Definition array.hpp:552
ARENE_NORETURN constexpr auto back() const noexcept -> T const &
Get a const-reference to the last element of the array.
Definition array.hpp:793
static constexpr std::integral_constant< bool, true > empty
Check if the array is empty, always true.
Definition array.hpp:594
static constexpr std::integral_constant< std::size_t, 0 > size
The number of elements in the array, which is always 0.
Definition array.hpp:579
friend constexpr auto operator==(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Compares two arrays lexicographically. Compares the left and right operands.
Definition array.hpp:837
ARENE_NORETURN constexpr auto at(std::size_t) -> T &
Get a reference to the index'th element of the array.
Definition array.hpp:713
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Get a const_reverse_iterator that references the last element of the array.
Definition array.hpp:650
T const * const_pointer
The type of a pointer to a const array element.
Definition array.hpp:554
constexpr auto data() const noexcept -> T const *
Get a pointer to the first element of the const array.
Definition array.hpp:606
static constexpr std::integral_constant< std::size_t, 0 > max_size
The maximum number of elements in the array, which is always 0.
Definition array.hpp:587
ARENE_NORETURN constexpr auto back() noexcept -> T &
Get a const-reference to the last element of the array.
Definition array.hpp:777
std::ptrdiff_t difference_type
The type for the distance between two iterators.
Definition array.hpp:562
::arene::base::reverse_iterator< iterator > reverse_iterator
An iterator for iteration through the array in reverse order.
Definition array.hpp:570
friend constexpr auto operator>(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Compares two arrays lexicographically. Compares the left and right operands.
Definition array.hpp:853
static constexpr void fill(T const &) noexcept
Set every element in the array to the provided value. This is a noop for an empty array.
Definition array.hpp:805
ARENE_NORETURN constexpr auto at(std::size_t) const -> T const &
Get a const-reference to the index'th element of the array.
Definition array.hpp:730
static constexpr auto crbegin() noexcept -> const_reverse_iterator
Get a const_reverse_iterator that references the last element of the array.
Definition array.hpp:669
friend constexpr void swap(array &, array &) noexcept
Swap all the elements with another array. This is a noop for an empty array.
Definition array.hpp:818
constexpr auto end() noexcept -> iterator
Get an iterator that references one-past the last element of the array.
Definition array.hpp:619
friend constexpr auto operator<=(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Compares two arrays lexicographically. Compares the left and right operands.
Definition array.hpp:849
::arene::base::reverse_iterator< const_iterator > const_reverse_iterator
An iterator for iteration through the array in reverse order that treats the elements as const.
Definition array.hpp:572
T const & const_reference
The type of a reference to a const array element.
Definition array.hpp:558
detail::wrapped_iterator< pointer, array_detail::array_iter_passkey > iterator
An iterator for the array.
Definition array.hpp:565
friend constexpr auto operator>=(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Compares two arrays lexicographically. Compares the left and right operands.
Definition array.hpp:857
T & reference
The type of a reference to an array element.
Definition array.hpp:556
constexpr auto data() noexcept -> T *
Get a pointer to the first element of the array.
Definition array.hpp:600
ARENE_NORETURN constexpr auto front() const noexcept -> T const &
Get a const-reference to the first element of the array.
Definition array.hpp:761
friend constexpr auto operator!=(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Compares two arrays lexicographically. Compares the left and right operands.
Definition array.hpp:841
constexpr auto end() const noexcept -> const_iterator
Get a const_iterator that references one past the last element of the array.
Definition array.hpp:631
constexpr auto rbegin() noexcept -> reverse_iterator
Get an reverse_iterator that references the last element of the array.
Definition array.hpp:638
std::size_t size_type
The type returned by size()
Definition array.hpp:560
T value_type
The type of each array element.
Definition array.hpp:550
detail::wrapped_iterator< const_pointer, array_detail::array_iter_passkey > const_iterator
An iterator for the array that treats the elements as const.
Definition array.hpp:567
constexpr auto begin() noexcept -> iterator
Get an iterator that references the first element of the array.
Definition array.hpp:613
A fixed-size array of T objects.
Definition array.hpp:77
friend constexpr auto operator==(array const &lhs, array const &rhs) noexcept -> bool
Compare all elements in two arrays for equality.
Definition array.hpp:303
::arene::base::reverse_iterator< const_iterator > const_reverse_iterator
An iterator for iteration through the array in reverse order that treats the elements as const.
Definition array.hpp:112
constexpr auto cend() const noexcept -> const_iterator
Definition array.hpp:201
byte values_[N]
Definition array.hpp:526
friend constexpr auto operator<(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Imparts a lexicographic ordering of two arrays.
Definition array.hpp:445
static constexpr auto three_way_compare(array const &lhs, array< T, UN > const &rhs) noexcept -> arene::base::strong_ordering
Imparts a lexicographic ordering of two arrays. Compares the left and right operands.
Definition array.hpp:395
constexpr auto end() noexcept -> iterator
Obtain an iterator to the one-passed-the-end of the array.
Definition array.hpp:163
std::ptrdiff_t difference_type
The type for the distance between two iterators.
Definition array.hpp:102
T * pointer
The type of a pointer to an array element.
Definition array.hpp:92
constexpr auto back() noexcept -> T &
Get a const-reference to the last element of the array.
Definition array.hpp:284
static constexpr std::integral_constant< std::size_t, N > max_size
Definition array.hpp:130
T const * const_pointer
The type of a pointer to a const array element.
Definition array.hpp:94
detail::wrapped_iterator< const_pointer, array_detail::array_iter_passkey > const_iterator
An iterator for the array that treats the elements as const.
Definition array.hpp:107
static constexpr std::integral_constant< std::size_t, N > size
Definition array.hpp:119
constexpr auto begin() const noexcept -> const_iterator
Obtain an iterator to the first element of the array.
Definition array.hpp:172
friend constexpr auto operator==(array const &, array< T, UN > const &) noexcept -> bool
Arrays with different sizes are not equal.
Definition array.hpp:311
static constexpr auto three_way_compare(array const &, array< T, 0 > const &) noexcept -> arene::base::strong_ordering
Imparts a lexicographic ordering of two arrays. Compares the left and right operands.
Definition array.hpp:400
::arene::base::reverse_iterator< iterator > reverse_iterator
An iterator for iteration through the array in reverse order.
Definition array.hpp:110
constexpr auto rbegin() noexcept -> reverse_iterator
Obtain a reverse_iterator to the last element of the array.
Definition array.hpp:181
constexpr auto front() const noexcept -> T const &
Get a const-reference to the first element of the array.
Definition array.hpp:279
constexpr auto rend() const noexcept -> const_reverse_iterator
Obtai a const_reverse_iterator that references one before the first element of the array.
Definition array.hpp:193
constexpr auto back() const noexcept -> T const &
Get a const-reference to the last element of the array.
Definition array.hpp:289
constexpr auto front() noexcept -> T &
Get a reference to the first element of the array.
Definition array.hpp:274
T & reference
The type of a reference to an array element.
Definition array.hpp:96
std::size_t size_type
The type returned by size()
Definition array.hpp:100
constexpr auto data() const noexcept -> T const *
Obtain a pointer to the first element of the array.
Definition array.hpp:149
T value_type
The type of each array element.
Definition array.hpp:90
constexpr auto end() const noexcept -> const_iterator
Obtain an iterator to the one-passed-the-end of the array.
Definition array.hpp:176
detail::wrapped_iterator< pointer, array_detail::array_iter_passkey > iterator
An iterator for the array.
Definition array.hpp:105
constexpr auto crend() const noexcept -> const_reverse_iterator
Obtain a const_reverse_iterator that references one before the first element of the array.
Definition array.hpp:209
constexpr auto operator[](std::size_t index) const noexcept -> T const &
Get a reference to the n'th element of the array.
Definition array.hpp:229
friend constexpr auto operator>(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Imparts a lexicographic ordering of two arrays.
Definition array.hpp:453
constexpr auto cbegin() const noexcept -> const_iterator
Definition array.hpp:197
friend constexpr auto operator<=(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Imparts a lexicographic ordering of two arrays.
Definition array.hpp:449
constexpr auto at(std::size_t index) const -> T const &
Get a reference to the n'th element of the array, or throw.
Definition array.hpp:264
constexpr auto operator[](std::size_t index) noexcept -> T &
Get a reference to the n'th element of the array.
Definition array.hpp:220
friend constexpr auto operator!=(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Inequality compare all elements in the array.
Definition array.hpp:374
constexpr void fill(T const &val) noexcept(std::is_nothrow_copy_assignable< T >::value)
Set every element in the array to the provided value.
Definition array.hpp:472
friend constexpr auto operator>=(array const &lhs, array< T, UN > const &rhs) noexcept -> bool
Imparts a lexicographic ordering of two arrays.
Definition array.hpp:457
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Obtain a reverse_iterator to the last element of the array.
Definition array.hpp:189
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Obtain a const_reverse_iterator that references the last element of the array.
Definition array.hpp:205
static constexpr std::integral_constant< bool, false > empty
Definition array.hpp:139
static constexpr auto fast_inequality_check(array const &lhs, array< T, UN > const &rhs) noexcept -> arene::base::inequality_heuristic
Quickly checks two arrays for inequality to see if a more costly full ordering check is needed.
Definition array.hpp:419
constexpr auto rend() noexcept -> reverse_iterator
Obtain a reverse_iterator that references one-before the first element of the array.
Definition array.hpp:185
constexpr void swap(array &other) noexcept(is_nothrow_swappable_v< U >)
swaps all the elements this array and another.
Definition array.hpp:491
constexpr auto data() noexcept -> T *
Obtain a pointer to the first element of the array.
Definition array.hpp:145
T const & const_reference
The type of a reference to a const array element.
Definition array.hpp:98
friend constexpr void swap(array &lhs, array &rhs) noexcept(noexcept(lhs.swap(rhs)))
swaps all the elements between two arrays.
Definition array.hpp:512
constexpr auto begin() noexcept -> iterator
Obtain an iterator to the first element of the array.
Definition array.hpp:158
constexpr auto at(std::size_t index) -> T &
Get a reference to the n'th element of the array, or throw.
Definition array.hpp:248
A backport of the constexpr std::reverse_iterator from C++17.
Definition reverse_iterator.hpp:188
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
static constexpr value_type value
Definition integral_constant.hpp:34
T type
The type of the element at index N.
Definition array.hpp:949
obtains the type of the specified element
Definition tuple_element.hpp:28
obtain the number of elements in a tuple-like type
Definition tuple_size.hpp:22
#define ARENE_INVARIANT_UNREACHABLE(message)
Terminate the application if this line is ever executed. The supplied message will be output in that ...
Definition contract.hpp:170
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Provides implementation of a backport of C++20's version of std::equal.
Provides an implementation of a backport of std::lexicographical_compare from C++20.
static ARENE_MAYBE_UNUSED constexpr auto const & swap
A Customization Point Object implementation of the constexpr compatible std::swap from C++17.
Definition swap.hpp:130
Definition accumulate.hpp:37
constexpr bool is_nothrow_swappable_v
Trait query indicating if a type can be noexcept-swapped.
constexpr std::integral_constant< std::size_t, N > array< T, N >::size
Definition array.hpp:534
constexpr std::integral_constant< bool, false > array< T, N >::empty
Definition array.hpp:540
strong_ordering_detail::strong_ordering strong_ordering
The enumeration specifying the result of an ordering comparison.
Definition strong_ordering.hpp:147
three_way_compare_detail::compare_three_way compare_three_way
Function object that does a three-way comparison between operands, equivalent to std::compare_three_w...
Definition compare_three_way.hpp:214
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
inequality_heuristic
An enumeration used for the return value of fast_inequality_check functions to indicate if two values...
Definition operators.hpp:696
@ may_be_equal_or_not_equal
The values checked may or may not be equal to each other; a more detailed check is required.
Definition operators.hpp:700
@ definitely_not_equal
The two values checked are definitely not equal to each other.
Definition operators.hpp:698
Definition accumulate.hpp:36
::ptrdiff_t ptrdiff_t
A type suitable for holding the difference between two pointers.
Definition cstddef.hpp:31
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
#define ARENE_NORETURN
An alias for [[noreturn]] , or a no-op if the attribute is not supported.
Definition noreturn.hpp:24
Provides a backport of the constexpr implementation of std::reverse_iterator .