5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTEGER_SEQUENCES_INTEGER_SEQUENCE_OPS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTEGER_SEQUENCES_INTEGER_SEQUENCE_OPS_HPP_
12#include "arene/base/iterator/next.hpp"
13#include "arene/base/stdlib_choice/cstddef.hpp"
14#include "arene/base/stdlib_choice/initializer_list.hpp"
15#include "arene/base/stdlib_choice/integer_sequence.hpp"
16#include "arene/base/stdlib_choice/integral_constant.hpp"
17#include "arene/base/type_traits/conditional.hpp"
24namespace integer_sequence_ops_detail {
27template <
typename... Sequences>
28struct integer_sequence_cat_impl {};
33template <
typename T, T... Elements>
34struct integer_sequence_cat_impl<std::integer_sequence<T, Elements...>> {
36 using type = std::integer_sequence<T, Elements...>;
44template <
typename T, T... SequenceElements1, T... SequenceElements2>
45struct integer_sequence_cat_impl<
46 std::integer_sequence<T, SequenceElements1...>,
47 std::integer_sequence<T, SequenceElements2...>> {
51 using type = std::integer_sequence<T, SequenceElements1..., SequenceElements2...>;
57template <
typename Sequence1,
typename... OtherSequences>
58struct integer_sequence_cat_impl<Sequence1, OtherSequences...> {
62 typename integer_sequence_cat_impl<Sequence1,
typename integer_sequence_cat_impl<OtherSequences...>::type>::type;
72template <
typename... Sequences>
73using integer_sequence_cat =
typename integer_sequence_ops_detail::integer_sequence_cat_impl<Sequences...>::type;
80template <std::size_t Index,
typename Sequence,
bool = (Index < Sequence::size())>
83namespace integer_sequence_ops_detail {
91template <std::size_t Index,
typename T, T... Elements>
92constexpr auto get_integer_sequence_element(std::integer_sequence<T, Elements...>)
noexcept -> T {
93 static_assert(Index <
sizeof...(Elements),
"Index must be in range of the sequence");
94 return *(arene::base::next(std::initializer_list<T>{Elements...}.begin(),
static_cast<std::ptrdiff_t>(Index)));
116namespace integer_sequence_ops_detail {
124template <
typename T, T... Elements>
125constexpr auto integer_sequence_contains(T value, std::integer_sequence<T, Elements...>)
noexcept ->
bool {
126 for (T
const element : {Elements...}) {
127 if (element == value) {
137constexpr auto integer_sequence_contains(T, std::integer_sequence<T>)
noexcept ->
bool {
160namespace integer_sequence_ops_detail {
168constexpr auto get_integer_sequence_index_of_impl(T value, std::initializer_list<T> elements)
noexcept -> std::size_t {
169 std::size_t index{0U};
170 for (T
const element : elements) {
171 if (element == value) {
185template <
typename T, T Value, T... Elements>
186constexpr auto get_integer_sequence_index_of(std::integer_sequence<T, Elements...>)
noexcept -> std::size_t {
187 constexpr std::size_t index{get_integer_sequence_index_of_impl(Value, {Elements...})};
188 static_assert(index <
sizeof...(Elements),
"Value must be in input sequence!");
212namespace integer_sequence_ops_detail {
219template <
typename T, T... Elements>
220constexpr auto get_integer_sequence_count_of(T value, std::integer_sequence<T, Elements...>)
noexcept -> std::size_t {
221 std::size_t count{0U};
222 for (T
const element : {Elements...}) {
223 if (element == value) {
233constexpr auto get_integer_sequence_count_of(T, std::integer_sequence<T>)
noexcept -> std::size_t {
244template <
typename Sequence,
typename Sequence::value_type Value>
257namespace integer_sequence_ops_detail {
265template <
typename Sequence>
266class integer_sequence_unique_elements_impl;
274class integer_sequence_unique_elements_impl<std::integer_sequence<T>> {
277 using type = std::integer_sequence<T>;
287template <
typename UniqueSequence,
typename Sequence2>
288class integer_sequence_merge_unique_elements_impl;
297template <
typename UniqueSequence,
typename T>
298class integer_sequence_merge_unique_elements_impl<UniqueSequence, std::integer_sequence<T>> {
301 using type = UniqueSequence;
311template <
typename T, T... UniqueElements, T FirstElement, T... OtherElements>
312class integer_sequence_merge_unique_elements_impl<
313 std::integer_sequence<T, UniqueElements...>,
314 std::integer_sequence<T, FirstElement, OtherElements...>> {
317 using unique_sequence = std::integer_sequence<T, UniqueElements...>;
319 using remainder_sequence = std::integer_sequence<T, OtherElements...>;
323 using type =
typename conditional_t<
324 integer_sequence_contains_v<unique_sequence, FirstElement>,
325 integer_sequence_merge_unique_elements_impl<unique_sequence, remainder_sequence>,
326 integer_sequence_merge_unique_elements_impl<
327 std::integer_sequence<T, UniqueElements..., FirstElement>,
328 remainder_sequence>>::type;
Get the number of occurrences of a value in the provided sequence. The result is stored in the value ...
Definition integer_sequence_ops.hpp:248
Trait providing the Index th element of a std::integer_sequence. The value member holds the value....
Definition integer_sequence_ops.hpp:81
Definition array_exceptions_disabled.cpp:11
constexpr auto integer_sequence_element_v
The value of the Index th element of a std::integer_sequence.
constexpr bool integer_sequence_contains_v
Checks if the specified integer sequence contains the specified value.
constexpr std::size_t integer_sequence_index_of_v
The index of the first occurrence of a value in a std::integer_sequence.
constexpr std::size_t integer_sequence_count_of_v
Get the number of occurrences of a value in the provided sequence.
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10
Trait for the index of the first occurrence of a value in a std::integer_sequence.
Definition integer_sequence_ops.hpp:158