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_
14#include "arene/base/stdlib_choice/cstddef.hpp"
15#include "arene/base/stdlib_choice/initializer_list.hpp"
16#include "arene/base/stdlib_choice/integer_sequence.hpp"
17#include "arene/base/stdlib_choice/integral_constant.hpp"
25namespace integer_sequence_ops_detail {
28template <
typename... Sequences>
29struct integer_sequence_cat_impl {};
34template <
typename T, T... Elements>
35struct integer_sequence_cat_impl<std::integer_sequence<T, Elements...>> {
37 using type = std::integer_sequence<T, Elements...>;
45template <
typename T, T... SequenceElements1, T... SequenceElements2>
46struct integer_sequence_cat_impl<
47 std::integer_sequence<T, SequenceElements1...>,
48 std::integer_sequence<T, SequenceElements2...>> {
52 using type = std::integer_sequence<T, SequenceElements1..., SequenceElements2...>;
58template <
typename Sequence1,
typename... OtherSequences>
59struct integer_sequence_cat_impl<Sequence1, OtherSequences...> {
63 typename integer_sequence_cat_impl<Sequence1,
typename integer_sequence_cat_impl<OtherSequences...>::type>::type;
73template <
typename... Sequences>
74using integer_sequence_cat =
typename integer_sequence_ops_detail::integer_sequence_cat_impl<Sequences...>::type;
81template <std::
size_t Index,
typename Sequence,
bool = (Index < Sequence::size())>
82class integer_sequence_element {};
84namespace
integer_sequence_ops_detail {
92template <std::
size_t Index,
typename T, T... Elements>
94 static_assert(Index <
sizeof...(Elements),
"Index must be in range of the sequence");
103template <
std::size_t Index,
typename T, T... Elements>
104class integer_sequence_element<Index,
std::integer_sequence<T, Elements...>, true>
107 integer_sequence_ops_detail::get_integer_sequence_element<Index>(std::integer_sequence<T, Elements...>{})> {};
114template <std::
size_t Index,
typename Sequence>
115extern constexpr auto integer_sequence_element_v = integer_sequence_element<Index, Sequence>::value;
117namespace integer_sequence_ops_detail {
125template <
typename T, T... Elements>
127 for (T
const element : {Elements...}) {
128 if (element == value) {
138constexpr auto integer_sequence_contains(T, std::integer_sequence<T>)
noexcept ->
bool {
148template <
typename Sequence,
typename Sequence::value_type Value>
150 integer_sequence_ops_detail::integer_sequence_contains(Value, Sequence{});
158template <
typename Sequence,
typename Sequence::value_type Value,
bool =
integer_sequence_contains_v<Sequence, Value>>
161namespace integer_sequence_ops_detail {
171 for (T
const element : elements) {
172 if (element == value) {
186template <
typename T, T Value, T... Elements>
187constexpr auto get_integer_sequence_index_of(std::integer_sequence<T, Elements...>)
noexcept ->
std::size_t {
188 constexpr std::size_t index{get_integer_sequence_index_of_impl(Value, {Elements...})};
189 static_assert(index <
sizeof...(Elements),
"Value must be in input sequence!");
197template <
typename Sequence,
typename Sequence::value_type Value>
198class integer_sequence_index_of<Sequence, Value, true>
199 :
public std::integral_constant<
201 integer_sequence_ops_detail::get_integer_sequence_index_of<typename Sequence::value_type, Value>(Sequence{}
210template <
typename Sequence,
typename Sequence::value_type Value>
213namespace integer_sequence_ops_detail {
220template <
typename T, T... Elements>
221constexpr auto get_integer_sequence_count_of(T value, std::integer_sequence<T, Elements...>)
noexcept ->
std::size_t {
223 for (T
const element : {Elements...}) {
224 if (element == value) {
234constexpr auto get_integer_sequence_count_of(T, std::integer_sequence<T>)
noexcept ->
std::size_t {
245template <
typename Sequence,
typename Sequence::value_type Value>
249 integer_sequence_ops_detail::get_integer_sequence_count_of(Value, Sequence{})> {};
255template <
typename Sequence,
typename Sequence::value_type Value>
258namespace integer_sequence_ops_detail {
266template <
typename Sequence>
267class integer_sequence_unique_elements_impl;
275class integer_sequence_unique_elements_impl<
std::integer_sequence<T>> {
288template <
typename UniqueSequence,
typename Sequence2>
289class integer_sequence_merge_unique_elements_impl;
298template <
typename UniqueSequence,
typename T>
299class integer_sequence_merge_unique_elements_impl<UniqueSequence,
std::integer_sequence<T>> {
302 using type = UniqueSequence;
312template <
typename T, T... UniqueElements, T FirstElement, T... OtherElements>
313class integer_sequence_merge_unique_elements_impl<
314 std::integer_sequence<T, UniqueElements...>,
324 using type =
typename conditional_t<
325 integer_sequence_contains_v<unique_sequence, FirstElement>,
326 integer_sequence_merge_unique_elements_impl<unique_sequence, remainder_sequence>,
327 integer_sequence_merge_unique_elements_impl<
329 remainder_sequence>>::type;
340template <
typename Sequence>
342 integer_sequence_merge_unique_elements_impl<std::integer_sequence<typename Sequence::value_type>, 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:249
Implementation of std::initializer_list for brace initialization.
Definition initializer_list.hpp:21
constexpr auto begin() const noexcept -> iterator
Get a pointer to the first element.
Definition initializer_list.hpp:46
Implements a compile-time sequence of integers.
Definition integer_sequence.hpp:32
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
Definition accumulate.hpp:37
ARENE_NODISCARD constexpr auto next(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator
Produces the Nth successor (or predecessor if steps is negative) of an iterator.
Definition next.hpp:38
constexpr bool integer_sequence_contains_v
Checks if the specified integer sequence contains the specified value.
typename integer_sequence_ops_detail:: integer_sequence_merge_unique_elements_impl< std::integer_sequence< typename Sequence::value_type >, Sequence >::type integer_sequence_unique_elements
Create a new integer sequence with the unique values from the provided integer sequence....
Definition integer_sequence_ops.hpp:341
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.
typename integer_sequence_ops_detail::integer_sequence_cat_impl< Sequences... >::type integer_sequence_cat
Produces a single std::integer_sequence which is the concatenation of multiple std::integer_sequence.
Definition integer_sequence_ops.hpp:74
Definition accumulate.hpp:36
::ptrdiff_t ptrdiff_t
A type suitable for holding the difference between two pointers.
Definition cstddef.hpp:31
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
Trait for the index of the first occurrence of a value in a std::integer_sequence.
Definition integer_sequence_ops.hpp:159