Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
sequential_values.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_INTEGER_SEQUENCES_SEQUENTIAL_VALUES_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTEGER_SEQUENCES_SEQUENTIAL_VALUES_HPP_
7
8// IWYU pragma: private, include "arene/base/integer_sequences.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"
12#include "arene/base/array/array.hpp"
13#include "arene/base/constraints/constraints.hpp"
14#include "arene/base/integer_sequences/make_integer_sequence.hpp"
15#include "arene/base/stdlib_choice/cstddef.hpp"
16#include "arene/base/stdlib_choice/enable_if.hpp"
17#include "arene/base/stdlib_choice/integer_sequence.hpp"
18
19// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
20
21namespace arene {
22namespace base {
23
24namespace sequential_values_detail {
25
26/// @brief The maximum number of elements supported by @c sequential_values and @c make_index_sequence_array
27/// On certain platforms and compilers, there is a limit to the number of elements that can be expanded in an
28/// initializer list. For the currently supported set of compilers, the lower bound of this is 2^16-1 in clang-17.
29static constexpr std::size_t max_number_of_elements{65535U};
30
31/// @brief Tests if a sequential values count is valid
32/// @tparam NumElements the number of elements desired
33/// @return true if <c> NumElements <= max_number_of_elements </c>
34/// @return false otherwise
35template <std::size_t NumElements>
36extern constexpr bool is_valid_size_v = NumElements <= max_number_of_elements;
37
38/// @brief Create an array holding the values in the provided index sequence.
39/// @tparam ElementType The type of each element
40/// @tparam Indices The values to put in the array
41/// @return An array holding the values, The array bounds is the number of indices in the sequence.
42template <
43 typename ElementType,
44 ElementType... Indices,
45 constraints<std::enable_if_t<sequential_values_detail::is_valid_size_v<sizeof...(Indices)>>> = nullptr>
46constexpr auto make_index_sequence_array(std::integer_sequence<ElementType, Indices...>)
47 -> array<ElementType, sizeof...(Indices)> {
48 // parasoft-begin-suppress AUTOSAR-M8_5_2-a-2 "False positive: correct initialization"
49 return {Indices...};
50 // parasoft-end-suppress AUTOSAR-M8_5_2-a-2
51}
52
53} // namespace sequential_values_detail
54
55/// @brief An array holding a sequence of integer values starting at Begin, incrementing by 1 each time.
56/// @tparam ElementType The type of each element
57/// @tparam Begin The first element in the sequence.
58/// @tparam Count The number of elements in the sequence.
59template <
60 typename ElementType,
66);
67
68/// @brief An array holding a sequence of integer values starting at Begin, ending at End and incrementing by 1 each
69/// time.
70/// @tparam ElementType The type of each element
71/// @tparam Begin The first element in the sequence.
72/// @tparam End The last element in the sequence.
73template <
74 typename ElementType,
78extern constexpr auto sequential_values_between =
80
81/// @brief An array holding a sequence of integer values starting at 0, incrementing by 1 each time.
82/// @tparam ElementType The type of each element
83/// @tparam Count The number of elements in the sequence.
84template <
85 typename ElementType,
89
90} // namespace base
91} // namespace arene
92
93#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTEGER_SEQUENCES_SEQUENTIAL_VALUES_HPP_
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10