Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
array.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ARRAY_ARRAY_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ARRAY_ARRAY_HPP_
7
8// IWYU pragma: private, include "arene/base/array.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
20#include "arene/base/detail/exceptions.hpp"
21#include "arene/base/detail/wrapped_iterator.hpp" // IWYU pragma: keep
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"
35// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
36
37// parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Mixed comparisons permitted by A13-5-5 Permit #1"
38
39namespace arene {
40namespace base {
41
42// IWYU pragma: begin_keep
43template <typename T, std::size_t N>
44class array;
45// IWYU pragma: end_keep
46
47namespace array_detail {
48// parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "Passkey idiom permitted by A11-3-1 Permit #1"
49/// @brief A passkey type to restrict constructing array iterators to array.
50class array_iter_passkey {
51 private:
52 /// @brief The default constructor is explicit to prevent construction via {}.
53 explicit array_iter_passkey() noexcept = default;
54 template <typename T, std::size_t N>
55 friend class ::arene::base::array;
56};
57// parasoft-end-suppress AUTOSAR-A11_3_1-a-2
58
59/// @brief If exceptions are enabled, throws out of range. Otherwise, is an invariant violation as it should not be
60/// called.
61/// @note We have to use this method rather than the mixin because array must be an aggregate type, and in C++14 that
62/// means no base classes.
63/// @throws std::out_of_range if exceptions are enabled.
64// NOTE: This function is never defined if exceptions are disabled.
65ARENE_NORETURN void throw_out_of_range();
66} // namespace array_detail
67
68// parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: arene::base::array members cannot hide extents members"
69// parasoft-begin-suppress AUTOSAR-A12_1_1-b-2 "False positive: arene::base::array models std::array, which is an
70// Aggregate, and has no constructors"
71/// @brief A fixed-size array of T objects.
72///
73/// This is a backport of the @c constexpr @c std::array from C++17.
74/// @tparam T The type of the element held by the array
75/// @tparam N The number of elements in the array
76template <typename T, std::size_t N>
77class array {
78 // parasoft-begin-suppress CERT_C-PRE31-c "False positive: static_assert is a compile-time assert and can have no
79 // side-effects"
80 static_assert(
81 N <= std::numeric_limits<std::ptrdiff_t>::max(),
82 "Array size must be less than the maximum value of std::ptrdiff_t."
83 );
84 // parasoft-end-suppress CERT_C-PRE31-c
85
86 public:
87 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: Identifiers do not hide content in unrelated detail
88 // types"
89 /// @brief The type of each array element
90 using value_type = T;
91 /// @brief The type of a pointer to an array element
92 using pointer = T*;
93 /// @brief The type of a pointer to a const array element
94 using const_pointer = T const*;
95 /// @brief The type of a reference to an array element
96 using reference = T&;
97 /// @brief The type of a reference to a const array element
98 using const_reference = T const&;
99 /// @brief The type returned by @c size()
101 /// @brief The type for the distance between two iterators
103
104 /// @brief An iterator for the array
105 using iterator = detail::wrapped_iterator<pointer, array_detail::array_iter_passkey>;
106 /// @brief An iterator for the array that treats the elements as @c const
107 using const_iterator = detail::wrapped_iterator<const_pointer, array_detail::array_iter_passkey>;
108
109 /// @brief An iterator for iteration through the array in reverse order.
111 /// @brief An iterator for iteration through the array in reverse order that treats the elements as @c const.
113
114 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
115 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size' does not hide anything"
116 // exposed as part of the API"
117 /// @brief The number of elements in the array, which is always @c N
118 /// @return The size of the array, N
120 // parasoft-end-suppress AUTOSAR-A2_10_1-d
121 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
122
123 // parasoft-end-suppress AUTOSAR-A2_10_1-e "False positive: Identifiers do not hide content in unrelated detail types"
124
125 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'max_size' does not hide anything"
126 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
127 // exposed as part of the API"
128 /// @brief The maximum number of elements in the array, which is always @c N
129 /// @return The size of the array, N
131 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
132 // parasoft-end-suppress AUTOSAR-A2_10_1-e
133
134 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'empty' does not hide anything"
135 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
136 // exposed as part of the API"
137 /// @brief Check if the array is empty, always @c false
138 /// @return false
140 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
141 // parasoft-end-suppress AUTOSAR-A2_10_1-e
142
143 /// @brief Obtain a pointer to the first element of the array.
144 /// @return a pointer to the first element of the array.
145 constexpr auto data() noexcept -> T* { return values_; }
146
147 /// @brief Obtain a pointer to the first element of the array.
148 /// @return a pointer to the first element of the array, const-qualified.
149 constexpr auto data() const noexcept -> T const* { return values_; }
150
151 // parasoft-begin-suppress AUTOSAR-A8_4_2-a "False positive: these functions do return a value"
152 // parasoft-begin-suppress CERT_C-MSC37-a "False positive: these functions do return a value"
153 // parasoft-begin-suppress CERT_CPP-MSC52-a "False positive: these functions do return a value"
154 // parasoft-begin-suppress AUTOSAR-M9_3_3-a "False positive: these functions return instance data so can't be static"
155 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: these standard range API names do not hide anything"
156 /// @brief Obtain an iterator to the first element of the array.
157 /// @return an @c iterator that references the first element of the array.
158 constexpr auto begin() noexcept -> iterator { return {array_detail::array_iter_passkey{}, values_}; }
159
160 // parasoft-begin-suppress CERT_C-STR34-b "False positive: No char types used here"
161 /// @brief Obtain an iterator to the one-passed-the-end of the array.
162 /// @return an @c iterator that references one-past the last element of the array.
163 constexpr auto end() noexcept -> iterator { return begin() + static_cast<difference_type>(N); }
164 // parasoft-end-suppress CERT_C-STR34-b
165 // parasoft-end-suppress AUTOSAR-A8_4_2-a
166 // parasoft-end-suppress CERT_C-MSC37-a
167 // parasoft-end-suppress CERT_CPP-MSC52-a
168 // parasoft-end-suppress AUTOSAR-M9_3_3-a
169
170 /// @brief Obtain an iterator to the first element of the array.
171 /// @return a @c const_iterator that references the first element of the array.
172 constexpr auto begin() const noexcept -> const_iterator { return {array_detail::array_iter_passkey{}, values_}; }
173
174 /// @brief Obtain an iterator to the one-passed-the-end of the array.
175 /// @return a @c const_iterator that references one past the last element of the array.
176 constexpr auto end() const noexcept -> const_iterator { return begin() + static_cast<difference_type>(N); }
177
178 // parasoft-end-suppress AUTOSAR-A2_10_1-d
179 /// @brief Obtain a reverse_iterator to the last element of the array.
180 /// @return a @c reverse_iterator that references the last element of the array.
181 constexpr auto rbegin() noexcept -> reverse_iterator { return reverse_iterator(end()); }
182
183 /// @brief Obtain a @c reverse_iterator that references one-before the first element of the array.
184 /// @return a @c reverse_iterator that references one-before the first element of the array.
185 constexpr auto rend() noexcept -> reverse_iterator { return reverse_iterator(begin()); }
186
187 /// @brief Obtain a reverse_iterator to the last element of the array.
188 /// @return a @c const_reverse_iterator that references the last element of the array.
189 constexpr auto rbegin() const noexcept -> const_reverse_iterator { return const_reverse_iterator(cend()); }
190
191 /// @brief Obtai a @c const_reverse_iterator that references one before the first element of the array.
192 /// @return a @c const_reverse_iterator that references one before the first element of the array.
193 constexpr auto rend() const noexcept -> const_reverse_iterator { return const_reverse_iterator(cbegin()); }
194
195 /// @brief Obtain a @c const_iterator that references the first element of the array.
196 /// @return a @c const_iterator that references the first element of the array.
197 constexpr auto cbegin() const noexcept -> const_iterator { return begin(); }
198
199 /// @brief Obtain a @c const_iterator that references one past the last element of the array.
200 /// @return a @c const_iterator that references one past the last element of the array.
201 constexpr auto cend() const noexcept -> const_iterator { return end(); }
202
203 /// @brief Obtain a @c const_reverse_iterator that references the last element of the array.
204 /// @return a @c const_reverse_iterator that references the last element of the array.
205 constexpr auto crbegin() const noexcept -> const_reverse_iterator { return rbegin(); }
206
207 /// @brief Obtain a @c const_reverse_iterator that references one before the first element of the array.
208 /// @return a @c const_reverse_iterator that references one before the first element of the array.
209 constexpr auto crend() const noexcept -> const_reverse_iterator { return rend(); }
210
211 // parasoft-begin-suppress AUTOSAR-A0_1_4-a "False positive: parameter 'index' is used"
212 // parasoft-begin-suppress AUTOSAR-A8_4_2-a "ARENE_PRECONDITION terminates, so does not need a return"
213 // parasoft-begin-suppress CERT_C-MSC37-a "ARENE_PRECONDITION terminates, so does not need a return"
214 // parasoft-begin-suppress CERT_CPP-MSC52-a "ARENE_PRECONDITION terminates, so does not need a return"
215 /// @brief Get a reference to the n'th element of the array.
216 ///
217 /// @param index The index of the element to access.
218 /// @pre @c index Must be less than @c N or else @c ARENE_PRECONDITION violation.
219 /// @return A reference to that element
220 constexpr auto operator[](std::size_t index) noexcept -> T& {
221 ARENE_PRECONDITION(index < size());
222 return values_[index];
223 }
224 /// @brief Get a reference to the n'th element of the array.
225 ///
226 /// @param index The index of the element to access.
227 /// @pre @c index Must be less than @c N or else @c ARENE_PRECONDITION violation.
228 /// @return A reference to that element
229 constexpr auto operator[](std::size_t index) const noexcept -> T const& {
230 ARENE_PRECONDITION(index < size());
231 return values_[index];
232 }
233 // parasoft-end-suppress AUTOSAR-A8_4_2-a
234 // parasoft-end-suppress CERT_C-MSC37-a
235 // parasoft-end-suppress CERT_CPP-MSC52-a
236 // parasoft-end-suppress AUTOSAR-A0_1_4-a
237
238 /// @brief Get a reference to the n'th element of the array, or throw.
239 ///
240 /// @tparam AreExceptionsEnabled SFINAE flag to disable this method if exceptions are not enabled. Should not be
241 /// specified by the user.
242 /// @param index The index of the element to access.
243 /// @return A reference to that element
244 /// @throws std::out_of_range If index is not less than @c N
245 template <
246 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
248 constexpr auto at(std::size_t index) -> T& {
249 if (index >= size()) {
250 array_detail::throw_out_of_range();
251 }
252 return values_[index];
253 }
254 /// @brief Get a reference to the n'th element of the array, or throw.
255 ///
256 /// @tparam AreExceptionsEnabled Defaulted SFINAE flag to disable this method if exceptions are not enabled; should
257 /// not be specified by user.
258 /// @param index The index of the element to access.
259 /// @return A reference to that element
260 /// @throws std::out_of_range If index is not less than @c N
261 template <
262 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
264 constexpr auto at(std::size_t index) const -> T const& {
265 if (index >= size()) {
266 array_detail::throw_out_of_range();
267 }
268 return values_[index];
269 }
270
271 /// @brief Get a reference to the first element of the array.
272 ///
273 /// @return A reference to the first element
274 constexpr auto front() noexcept -> T& { return (*this)[0]; }
275
276 /// @brief Get a const-reference to the first element of the array.
277 ///
278 /// @return A reference to the first element
279 constexpr auto front() const noexcept -> T const& { return (*this)[0]; }
280
281 /// @brief Get a const-reference to the last element of the array.
282 ///
283 /// @return A reference to the last element
284 constexpr auto back() noexcept -> T& { return (*this)[N - 1U]; }
285
286 /// @brief Get a const-reference to the last element of the array.
287 ///
288 /// @return A reference to the last element
289 constexpr auto back() const noexcept -> T const& { return (*this)[N - 1U]; }
290
291 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: It is allowed to declare comparison operators as
292 // friend functions"
293 // parasoft-begin-suppress AUTOSAR-A2_7_3-a-2 "False positive: All overloads are fully are documented"
294 // parasoft-begin-suppress AUTOSAR-A2_7_3-b-2 "False positive: All overloads are fully are documented"
295 // parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: cannot apply static here"
296 /// @brief Compare all elements in two arrays for equality.
297 ///
298 /// @param lhs One of the arrays to compare.
299 /// @param rhs The other array to compare.
300 /// @return true if all elements in the arrays are equal.
301 /// @return false if any elements in the arrays are not equal, or the sizes of the arrays are different.
302 template <typename U = T, constraints<std::enable_if_t<is_equality_comparable_v<U>>> = nullptr>
303 friend constexpr auto operator==(array const& lhs, array const& rhs) noexcept -> bool {
304 return arene::base::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
305 }
306
307 /// @brief Arrays with different sizes are not equal.
308 ///
309 /// @return false because the arrays have different sizes.
310 template <std::size_t UN, typename U = T, constraints<std::enable_if_t<is_equality_comparable_v<U>>> = nullptr>
311 friend constexpr auto operator==(array const&, array<T, UN> const&) noexcept -> bool {
312 return false;
313 }
314
315 /// @brief Compare all elements in two arrays for equality.
316 ///
317 /// @param lhs One of the arrays to compare.
318 /// @param rhs The other array to compare.
319 /// @return true if all elements in the arrays are equal.
320 /// @return false if any elements in the arrays are not equal, or the sizes of the arrays are different.
321 template <
322 typename U = T,
327 friend constexpr auto operator==(array const& lhs, array const& rhs) noexcept -> bool {
328 return array::three_way_compare(lhs, rhs) == arene::base::strong_ordering::equal;
329 }
330
331 /// @brief Compare all elements in two arrays for equality.
332 ///
333 /// @param lhs One of the arrays to compare.
334 /// @param rhs The other array to compare.
335 /// @return true if all elements in the arrays are equal.
336 /// @return false if any elements in the arrays are not equal, or the sizes of the arrays are different.
337 template <
338 typename U = T,
343 friend constexpr auto operator==(array const& lhs, array const& rhs) noexcept -> bool {
345 (array::three_way_compare(lhs, rhs) == arene::base::strong_ordering::equal);
346 }
347
348 /// @brief Arrays with different sizes are not equal.
349 ///
350 /// @return false because the arrays have different sizes.
351 template <
352 std::size_t UN,
353 typename U = T,
355 nullptr>
356 friend constexpr auto operator==(array const&, array<T, UN> const&) noexcept -> bool {
357 return false;
358 }
359 // parasoft-end-suppress AUTOSAR-M3_3_2-a-2
360 // parasoft-end-suppress AUTOSAR-A2_7_3-b-2
361 // parasoft-end-suppress AUTOSAR-A2_7_3-a-2
362 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
363
364 // parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: cannot apply static here"
365 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: It is allowed to declare comparison operators as
366 // friend functions"
367 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
368 /// @brief Inequality compare all elements in the array.
369 /// @param lhs one of the arrays to compare
370 /// @param rhs the other array to compare
371 /// @return true if any elements in the arrays are not equal, or the sizes of the arrays are different.
372 /// @return false if all elements in the arrays are equal.
373 template <std::size_t UN, typename U = T>
374 friend constexpr auto operator!=(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
375 return !(lhs == rhs);
376 }
377 // parasoft-end-suppress CERT_C-EXP37-a-3
378 // parasoft-end-suppress AUTOSAR-M3_3_2-a-2
379 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
380
381 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'three_way_compare' does not hide anything"
382 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: It is allowed to declare comparison operators as
383 // friend functions"
384 // parasoft-begin-suppress AUTOSAR-A2_7_3-a-2 "False positive: All overloads are fully are documented"
385 // parasoft-begin-suppress AUTOSAR-A2_7_3-b-2 "False positive: All overloads are fully are documented"
386 /// @brief Imparts a lexicographic ordering of two arrays.
387 /// Compares the left and right operands.
388 /// @return arene::base::strong_ordering::less if the first element which compares unequal between
389 /// @c rhs and @c lhs also compares less-than, or if @c lhs is a strict prefix of @c rhs.
390 /// @return arene::base::strong_ordering::equal if all elements compare equal.
391 /// @return arene::base::strong_ordering::greater if the first element which compares unequal between
392 /// @c rhs and @c lhs also compares greater, or if @c rhs is a strict prefix of @c lhs.
393 /// @{
394 template <std::size_t UN, typename U = T, constraints<std::enable_if_t<compare_three_way_supported_v<U>>> = nullptr>
395 static constexpr auto three_way_compare(array const& lhs, array<T, UN> const& rhs) noexcept
397 return lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
398 }
399 template <typename U = T, constraints<std::enable_if_t<compare_three_way_supported_v<U>>> = nullptr>
400 static constexpr auto three_way_compare(array const&, array<T, 0> const&) noexcept -> arene::base::strong_ordering {
401 // This overload shouldn't need to exist, but there is a bug in GCC8 where a for-loop over 0 increments results in
402 // the containing function no longer being constexpr.
403 return arene::base::strong_ordering::greater;
404 }
405 /// @}
406 // parasoft-end-suppress AUTOSAR-A2_7_3-b-2
407 // parasoft-end-suppress AUTOSAR-A2_7_3-a-2
408 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
409 // parasoft-end-suppress AUTOSAR-A2_10_1-e
410
411 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'fast_inequality_check' does not hide anything"
412 /// @brief Quickly checks two arrays for inequality to see if a more costly full ordering check is needed
413 /// @param lhs one of the arrays to compare
414 /// @param rhs the other array to compare
415 /// @return @c arene::base::inequality_heuristic::definitely_not_equal if the two arrays have different sizes or if
416 /// any pair of their elements compare @c definitely_not_equal
417 /// @return @c arene::base::inequality_heuristic::may_be_equal_or_not_equal otherwise
418 template <std::size_t UN, typename U = T, constraints<std::enable_if_t<has_fast_inequality_check_v<U>>> = nullptr>
419 static constexpr auto fast_inequality_check(array const& lhs, array<T, UN> const& rhs) noexcept
421 if (size() != rhs.size()) {
423 }
424
425 for (size_type idx{}; idx < size(); ++idx) {
426 if (U::fast_inequality_check(lhs[idx], rhs[idx]) == arene::base::inequality_heuristic::definitely_not_equal) {
428 }
429 }
430
432 }
433 // parasoft-end-suppress AUTOSAR-A2_10_1-e
434
435 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: It is allowed to declare comparison operators as
436 // friend functions"
437 // parasoft-begin-suppress AUTOSAR-A2_7_3-a-2 "False positive: All overloads are fully are documented"
438 // parasoft-begin-suppress AUTOSAR-A2_7_3-b-2 "False positive: All overloads are fully are documented"
439 /// @brief Imparts a lexicographic ordering of two arrays.
440 /// @param lhs one of the arrays to compare
441 /// @param rhs the other array to compare
442 /// @see arene::base::array<T,N>::three_way_compare .
443 /// @{
444 template <std::size_t UN>
445 friend constexpr auto operator<(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
446 return array::three_way_compare(lhs, rhs) == arene::base::strong_ordering::less;
447 }
448 template <std::size_t UN>
449 friend constexpr auto operator<=(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
450 return array::three_way_compare(lhs, rhs) != arene::base::strong_ordering::greater;
451 }
452 template <std::size_t UN>
453 friend constexpr auto operator>(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
454 return array::three_way_compare(lhs, rhs) == arene::base::strong_ordering::greater;
455 }
456 template <std::size_t UN>
457 friend constexpr auto operator>=(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
458 return array::three_way_compare(lhs, rhs) != arene::base::strong_ordering::less;
459 }
460 /// @}
461 // parasoft-end-suppress AUTOSAR-A2_7_3-b-2
462 // parasoft-end-suppress AUTOSAR-A2_7_3-a-2
463 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
464
465 // parasoft-begin-suppress AUTOSAR-M0_1_8-a-2 "False positive: updates the 'values_' member"
466 /// @brief Set every element in the array to the provided value
467 /// @param val The value to use
468 template <
469 typename U = T,
471 nullptr>
472 constexpr void fill(T const& val) noexcept(std::is_nothrow_copy_assignable<T>::value) {
473 // parasoft-begin-suppress AUTOSAR-A18_1_1-a-2 "This class abstracts over the C array so users don't have to"
474 for (T& elem : values_) {
475 elem = val;
476 }
477 // parasoft-end-suppress AUTOSAR-A18_1_1-a-2
478 }
479 // parasoft-end-suppress AUTOSAR-M0_1_8-a-2
480
481 ///
482 /// @brief swaps all the elements this array and another.
483 ///
484 /// @tparam U the type of the elements in the array. Must satisfy @c is_swappable_v .
485 /// @param other the array to swap elements with
486 /// @post The elements in this array and @c other are exchanged 1:1. Relative order is maintained.
487 ///
488 template <
489 typename U = T,
491 constexpr void swap(array& other) noexcept(is_nothrow_swappable_v<U>) {
492 iterator rhs_iter{other.begin()};
493 for (auto& lhs_elem : *this) {
494 ::arene::base::swap(lhs_elem, *rhs_iter);
495 ++rhs_iter;
496 }
497 }
498
499 // parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: cannot apply static here"
500 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "Friend swap operators permitted by A11-3-1 Permit #2 v1.0.0"
501 ///
502 /// @brief swaps all the elements between two arrays.
503 ///
504 /// @tparam U the type of the elements in the array. Must satisfy @c is_swappable_v .
505 /// @param lhs the left hand array to swap.
506 /// @param rhs the right hand array to swap.
507 /// @post The elements in @c lhs and @c rhs are exchanged 1:1. Relative order is maintained.
508 ///
509 template <
510 typename U = T,
512 friend constexpr void swap(array& lhs, array& rhs) noexcept(noexcept(lhs.swap(rhs))) {
513 lhs.swap(rhs);
514 }
515 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
516 // parasoft-end-suppress AUTOSAR-M3_3_2-a-2
517
518 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "For arene::base::array to match the behaviour of std::array, values_
519 // must be public"
520 // parasoft-begin-suppress AUTOSAR-A18_1_1-a-2 "arene::base::array uses a C-style array so everywhere else can use
521 // arene::base::array instead"
522 /// @brief The actual elements of the @c array object. This must be a public member
523 /// to allow aggregate initialization, but users should treat it as private,
524 /// and only use the documented public interface.
525 // NOLINTNEXTLINE(hicpp-avoid-c-arrays,private-member-variables-in-classes,misc-non-private-member-variables-in-classes,readability-identifier-naming)
527 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
528 // parasoft-end-suppress AUTOSAR-A18_1_1-a-2
529};
530// parasoft-end-suppress AUTOSAR-A12_1_1-b-2
531// parasoft-end-suppress AUTOSAR-A2_10_1-e
532
533template <typename T, std::size_t N>
535
536template <typename T, std::size_t N>
538
539template <typename T, std::size_t N>
541
542// parasoft-begin-suppress AUTOSAR-A14_7_2-a-2 "False positive: This *is* the same file as the primary template declared
543// above"
544/// @brief Specialize for zero-sized arrays as 'T array[0]' is not standards compliant.
545/// @see arene::base::array
546template <typename T>
547class array<T, 0> {
548 public:
549 /// @brief The type of each array element
550 using value_type = T;
551 /// @brief The type of a pointer to an array element
552 using pointer = T*;
553 /// @brief The type of a pointer to a const array element
554 using const_pointer = T const*;
555 /// @brief The type of a reference to an array element
556 using reference = T&;
557 /// @brief The type of a reference to a const array element
558 using const_reference = T const&;
559 /// @brief The type returned by @c size()
561 /// @brief The type for the distance between two iterators
563
564 /// @brief An iterator for the array
565 using iterator = detail::wrapped_iterator<pointer, array_detail::array_iter_passkey>;
566 /// @brief An iterator for the array that treats the elements as @c const
567 using const_iterator = detail::wrapped_iterator<const_pointer, array_detail::array_iter_passkey>;
568
569 /// @brief An iterator for iteration through the array in reverse order.
571 /// @brief An iterator for iteration through the array in reverse order that treats the elements as @c const.
573
574 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
575 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size' does not hide anything"
576 // exposed as part of the API"
577 /// @brief The number of elements in the array, which is always 0
578 /// @return The size of the array, 0
580 // parasoft-end-suppress AUTOSAR-A2_10_1-d
581 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
582
583 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
584 // exposed as part of the API"
585 /// @brief The maximum number of elements in the array, which is always 0
586 /// @return The size of the array, 0
588 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
589
590 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
591 // exposed as part of the API"
592 /// @brief Check if the array is empty, always @c true
593 /// @return true
595 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
596
597 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
598 /// @brief Get a pointer to the first element of the array.
599 /// @return A null pointer
600 constexpr auto data() noexcept -> T* { return nullptr; }
601 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
602
603 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
604 /// @brief Get a pointer to the first element of the const array.
605 /// @return A null pointer
606 constexpr auto data() const noexcept -> T const* { return nullptr; }
607 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
608
609 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
610 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: these standard range API names do not hide anything"
611 /// @brief Get an iterator that references the first element of the array.
612 /// @return The iterator
613 constexpr auto begin() noexcept -> iterator { return {}; }
614 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
615
616 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
617 /// @brief Get an iterator that references one-past the last element of the array.
618 /// @return The iterator
619 constexpr auto end() noexcept -> iterator { return {}; }
620 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
621
622 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
623 /// @brief Get a const_iterator that references the first element of the array.
624 /// @return The iterator
625 constexpr auto begin() const noexcept -> const_iterator { return {}; }
626 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
627
628 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
629 /// @brief Get a const_iterator that references one past the last element of the array.
630 /// @return The iterator
631 constexpr auto end() const noexcept -> const_iterator { return {}; }
632 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
633 // parasoft-end-suppress AUTOSAR-A2_10_1-d
634
635 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
636 /// @brief Get an reverse_iterator that references the last element of the array.
637 /// @return The iterator
638 constexpr auto rbegin() noexcept -> reverse_iterator { return {}; }
639 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
640
641 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
642 /// @brief Get an reverse_iterator that references one-before the first element of the array.
643 /// @return The iterator
644 constexpr auto rend() noexcept -> reverse_iterator { return {}; }
645 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
646
647 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
648 /// @brief Get a const_reverse_iterator that references the last element of the array.
649 /// @return The iterator
650 constexpr auto rbegin() const noexcept -> const_reverse_iterator { return {}; }
651 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
652
653 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
654 /// @brief Get a const_reverse_iterator that references one before the first element of the array.
655 /// @return The iterator
656 constexpr auto rend() const noexcept -> const_reverse_iterator { return {}; }
657 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
658
659 /// @brief Get a const_iterator that references the first element of the array.
660 /// @return The iterator
661 static constexpr auto cbegin() noexcept -> const_iterator { return {}; }
662
663 /// @brief Get a const_iterator that references one past the last element of the array.
664 /// @return The iterator
665 static constexpr auto cend() noexcept -> const_iterator { return {}; }
666
667 /// @brief Get a const_reverse_iterator that references the last element of the array.
668 /// @return The iterator
669 static constexpr auto crbegin() noexcept -> const_reverse_iterator { return {}; }
670
671 /// @brief Get a const_reverse_iterator that references one before the first element of the array.
672 /// @return The iterator
673 static constexpr auto crend() noexcept -> const_reverse_iterator { return {}; }
674
675 // parasoft-begin-suppress AUTOSAR-A8_4_2-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
676 // parasoft-begin-suppress CERT_C-MSC37-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
677 // parasoft-begin-suppress CERT_CPP-MSC52-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
678 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
679 // parasoft-begin-suppress AUTOSAR-A2_7_3-a-2 "False positive: All overloads are fully are documented"
680 /// @brief Get a reference to the index'th element of the array.
681 /// @return Never returns
682 ///
683 /// @invariant Will always trigger @c ARENE_PRECONDITION
684 /// @{
685 ARENE_NORETURN constexpr auto operator[](std::size_t) noexcept -> T& {
687 ARENE_INVARIANT_UNREACHABLE("Precondition always fires");
688 }
689 ARENE_NORETURN constexpr auto operator[](std::size_t) const noexcept -> T const& {
691 ARENE_INVARIANT_UNREACHABLE("Precondition always fires");
692 }
693 /// @}
694 // parasoft-end-suppress AUTOSAR-A2_7_3-a-2
695 // parasoft-end-suppress CERT_C-EXP37-a-3
696 // parasoft-end-suppress CERT_CPP-MSC52-a-2
697 // parasoft-end-suppress CERT_C-MSC37-a-2
698 // parasoft-end-suppress AUTOSAR-A8-4-2-a-2
699
700 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
701 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
702 // parasoft-begin-suppress CERT_C-MSC37-a "False positive: these functions are marked NORETURN."
703 // parasoft-begin-suppress CERT_CPP-MSC52-a "False positive: these functions are marked NORETURN."
704 /// @brief Get a reference to the index'th element of the array.
705 /// @tparam AreExceptionsEnabled Defaulted SFINAE flag to disable this method if exceptions are not enabled; should
706 /// not be specified by user.
707 /// @return Never returns
708 ///
709 /// @throws std::out_of_range unconditionally
710 template <
711 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
713 ARENE_NORETURN constexpr auto at(std::size_t) -> T& {
714 array_detail::throw_out_of_range();
715 }
716 // parasoft-end-suppress CERT_C-EXP37-a-3
717 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
718
719 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
720 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
721 /// @brief Get a const-reference to the index'th element of the array.
722 /// @tparam AreExceptionsEnabled Defaulted SFINAE flag to disable this method if exceptions are not enabled; should
723 /// not be specified by user.
724 /// @return Never returns
725 ///
726 /// @throws std::out_of_range
727 template <
728 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
730 ARENE_NORETURN constexpr auto at(std::size_t) const -> T const& {
731 array_detail::throw_out_of_range();
732 }
733 // parasoft-end-suppress CERT_C-EXP37-a-3
734 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
735 // parasoft-begin-suppress CERT_C-MSC37-a
736 // parasoft-begin-suppress CERT_CPP-MSC52-a
737
738 // parasoft-begin-suppress AUTOSAR-A8_4_2-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
739 // parasoft-begin-suppress CERT_C-MSC37-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
740 // parasoft-begin-suppress CERT_CPP-MSC52-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
741 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
742 /// @brief Get a const-reference to the first element of the array.
743 ///
744 /// @return A reference to the first element
745 ARENE_NORETURN constexpr auto front() noexcept -> T& {
747 ARENE_INVARIANT_UNREACHABLE("Precondition always fires");
748 }
749 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
750 // parasoft-end-suppress CERT_CPP-MSC52-a-2
751 // parasoft-end-suppress CERT_C-MSC37-a-2
752 // parasoft-end-suppress AUTOSAR-A8-4-2-a-2
753
754 // parasoft-begin-suppress AUTOSAR-A8_4_2-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
755 // parasoft-begin-suppress CERT_C-MSC37-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
756 // parasoft-begin-suppress CERT_CPP-MSC52-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
757 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
758 /// @brief Get a const-reference to the first element of the array.
759 ///
760 /// @return A reference to the first element
761 ARENE_NORETURN constexpr auto front() const noexcept -> T const& {
763 ARENE_INVARIANT_UNREACHABLE("Precondition always fires");
764 }
765 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
766 // parasoft-end-suppress CERT_CPP-MSC52-a-2
767 // parasoft-end-suppress CERT_C-MSC37-a-2
768 // parasoft-end-suppress AUTOSAR-A8-4-2-a-2
769
770 // parasoft-begin-suppress AUTOSAR-A8_4_2-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
771 // parasoft-begin-suppress CERT_C-MSC37-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
772 // parasoft-begin-suppress CERT_CPP-MSC52-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
773 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
774 /// @brief Get a const-reference to the last element of the array.
775 ///
776 /// @return A reference to the last element
777 ARENE_NORETURN constexpr auto back() noexcept -> T& {
779 ARENE_INVARIANT_UNREACHABLE("Precondition always fires");
780 }
781 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
782 // parasoft-end-suppress CERT_CPP-MSC52-a-2
783 // parasoft-end-suppress CERT_C-MSC37-a-2
784 // parasoft-end-suppress AUTOSAR-A8-4-2-a-2
785
786 // parasoft-begin-suppress AUTOSAR-A8_4_2-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
787 // parasoft-begin-suppress CERT_C-MSC37-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
788 // parasoft-begin-suppress CERT_CPP-MSC52-a-2 "ARENE_PRECONDITION terminates, so does not need a return"
789 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: 'static' would prevent overloading on 'const'"
790 /// @brief Get a const-reference to the last element of the array.
791 ///
792 /// @return A reference to the last element
793 ARENE_NORETURN constexpr auto back() const noexcept -> T const& {
795 ARENE_INVARIANT_UNREACHABLE("Precondition always fires");
796 }
797 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
798 // parasoft-end-suppress CERT_CPP-MSC52-a-2
799 // parasoft-end-suppress CERT_C-MSC37-a-2
800 // parasoft-end-suppress AUTOSAR-A8-4-2-a-2
801
802 // parasoft-begin-suppress AUTOSAR-M0_1_8-b-2 "Required for consistency with API of primary template"
803 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
804 /// @brief Set every element in the array to the provided value. This is a noop for an empty array.
805 static constexpr void fill(T const&) noexcept {}
806 // parasoft-end-suppress CERT_C-EXP37-a-3
807 // parasoft-end-suppress AUTOSAR-M0_1_8-b-2
808
809 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
810 /// @brief Swap all the elements with another array. This is a noop for an empty array.
811 constexpr void swap(array&) noexcept {}
812 // parasoft-end-suppress CERT_C-EXP37-a-3
813
814 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "Friend swap operators permitted by A11-3-1 Permit #2 v1.0.0"
815 // parasoft-begin-suppress AUTOSAR-A0_1_3-a-2 "False positive: This is a public function, and doesn't need to be used
816 // in the translation unit"
817 /// @brief Swap all the elements with another array. This is a noop for an empty array.
818 friend constexpr void swap(array&, array&) noexcept {}
819 // parasoft-end-suppress AUTOSAR-A0_1_3-a-2
820 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
821
822 // parasoft-begin-suppress AUTOSAR-A2_7_3-a-2 "False positive: All overloads are fully are documented"
823 // parasoft-begin-suppress AUTOSAR-A2_7_3-b-2 "False positive: All overloads are fully are documented"
824 /// @brief Compares two arrays lexicographically.
825 /// Compares the left and right operands.
826 /// @return The equivalent of @c compare_three_way{}(0U,UN)
827 /// @{
828 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "Friend three_way_compare permitted by A11-3-1 Permit #2 v1.0.0""
829 template <std::size_t UN>
830 static constexpr auto three_way_compare(array const&, array<T, UN> const&) noexcept -> arene::base::strong_ordering {
831 return compare_three_way{}(0U, UN);
832 }
833 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
834 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: It is allowed to declare comparison operators as
835 // friend functions"
836 template <std::size_t UN>
837 friend constexpr auto operator==(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
838 return array::three_way_compare(lhs, rhs) == arene::base::strong_ordering::equal;
839 }
840 template <std::size_t UN>
841 friend constexpr auto operator!=(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
842 return !(lhs == rhs);
843 }
844 template <std::size_t UN>
845 friend constexpr auto operator<(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
846 return array::three_way_compare(lhs, rhs) == arene::base::strong_ordering::less;
847 }
848 template <std::size_t UN>
849 friend constexpr auto operator<=(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
850 return array::three_way_compare(lhs, rhs) != arene::base::strong_ordering::greater;
851 }
852 template <std::size_t UN>
853 friend constexpr auto operator>(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
854 return array::three_way_compare(lhs, rhs) == arene::base::strong_ordering::greater;
855 }
856 template <std::size_t UN>
857 friend constexpr auto operator>=(array const& lhs, array<T, UN> const& rhs) noexcept -> bool {
858 return array::three_way_compare(lhs, rhs) != arene::base::strong_ordering::less;
859 }
860 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
861 /// @}
862 // parasoft-end-suppress AUTOSAR-A2_7_3-b-2
863 // parasoft-end-suppress AUTOSAR-A2_7_3-a-2
864};
865// parasoft-end-suppress AUTOSAR-A14_7_2-a-2
866
867template <typename T>
869
870template <typename T>
872
873template <typename T>
875
876// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: cannot apply static here"
877/// @brief Get a reference to the element at the specified index in the array
878///
879/// @tparam I The index of the element to retrieve. Must satisfy @c I<N .
880/// @tparam T The type of the array elements
881/// @tparam N The number of array elements
882/// @param arr The array to retrieve the element from
883/// @return T& equivalent to @c arr[I] .
884template <std::size_t I, typename T, std::size_t N, constraints<std::enable_if_t<(I < N)>> = nullptr>
885constexpr auto get(array<T, N>& arr) noexcept -> T& {
886 return arr[I];
887}
888/// @brief Get a reference to the element at the specified index in the array
889///
890/// @tparam I The index of the element to retrieve. Must satisfy @c I<N .
891/// @tparam T The type of the array elements
892/// @tparam N The number of array elements
893/// @param arr The array to retrieve the element from
894/// @return T const& equivalent to @c arr[I] .
895template <std::size_t I, typename T, std::size_t N, constraints<std::enable_if_t<(I < N)>> = nullptr>
896constexpr auto get(array<T, N> const& arr) noexcept -> T const& {
897 return arr[I];
898}
899/// @brief Get a reference to the element at the specified index in the array
900///
901/// @tparam I The index of the element to retrieve. Must satisfy @c I<N .
902/// @tparam T The type of the array elements
903/// @tparam N The number of array elements
904/// @param arr The array to retrieve the element from
905/// @return T&& equivalent to @c std::move(arr[I]) .
906template <std::size_t I, typename T, std::size_t N, constraints<std::enable_if_t<(I < N)>> = nullptr>
907constexpr auto get(array<T, N>&& arr) noexcept -> T&& {
908 return std::move(arr[I]);
909}
910/// @brief Get a reference to the element at the specified index in the array
911///
912/// @tparam I The index of the element to retrieve. Must satisfy @c I<N .
913/// @tparam T The type of the array elements
914/// @tparam N The number of array elements
915/// @param arr The array to retrieve the element from
916/// @return T const&& equivalent to @c std::move(arr[I]) .
917template <std::size_t I, typename T, std::size_t N, constraints<std::enable_if_t<(I < N)>> = nullptr>
918constexpr auto get(array<T, N> const&& arr) noexcept -> T const&& {
919 // parasoft-begin-suppress AUTOSAR-A18_9_3-a "Moving is required to maintain rvalue qualification"
920 return std::move(arr[I]);
921 // parasoft-end-suppress AUTOSAR-A18_9_3-a "Moving is required to maintain rvalue qualification"
922}
923
924// parasoft-end-suppress AUTOSAR-M3_3_2-a
925
926} // namespace base
927} // namespace arene
928
929// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "False positive: specialization of standard templates is permitted"
930// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "False positive: specialization of standard templates is permitted"
931// parasoft-begin-suppress AUTOSAR-A11_0_2-a "False positive: inheritance from integral_constant is permitted"
932namespace std {
933/// @brief Specialization of @c std::tuple_size for @c arene::base::array
934/// @tparam T The type of the array elements
935/// @tparam N The number of array elements
936template <typename T, std::size_t N>
937class tuple_size<arene::base::array<T, N>> : public std::integral_constant<std::size_t, N> {};
938
939/// @brief Specialization of @c std::tuple_element for @c arene::base::array
940/// @tparam N The index of the element
941/// @tparam T The type of the array elements
942/// @tparam ArrN The number of array elements
943template <std::size_t N, typename T, std::size_t ArrN>
944class tuple_element<N, arene::base::array<T, ArrN>> {
945 static_assert(N < ArrN, "Index out of bounds in std::tuple_element<arene::base::array>");
946
947 public:
948 /// @brief The type of the element at index @c N
949 using type = T;
950};
951
952} // namespace std
953// parasoft-end-suppress AUTOSAR-A11_0_2-a "False positive: inheritance from integral_constant is permitted"
954// parasoft-end-suppress AUTOSAR-A17_6_1-a-2 "False positive: specialization of standard templates is permitted"
955// parasoft-end-suppress CERT_CPP-DCL58-a-2 "False positive: specialization of standard templates is permitted"
956
957// parasoft-end-suppress AUTOSAR-A11_3_1-a-2
958// parasoft-end-suppress AUTOSAR-A13_5_5-b-2
959
960#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ARRAY_ARRAY_HPP_
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
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 .