3#ifndef TETL_MDSPAN_INTEGRAL_CONSTANT_LIKE_HPP
4#define TETL_MDSPAN_INTEGRAL_CONSTANT_LIKE_HPP
15namespace etl::detail {
18concept pair_like =
true;
20template <
typename T,
typename IndexType>
21concept index_pair_like =
23 and etl::convertible_to<etl::tuple_element_t<0, T>, IndexType>
24 and etl::convertible_to<etl::tuple_element_t<1, T>, IndexType>
28concept integral_constant_like =
31 and etl::convertible_to<T,
decltype(T::value)>
38[[nodiscard]]
constexpr auto de_ice(T val) -> T
43template <
integral_constant_like T>
44[[nodiscard]]
constexpr auto de_ice(T )
49template <etl::
size_t K>
50[[nodiscard]]
constexpr auto nth_slice_specifier(
auto first,
auto... rest)
52 if constexpr (K == 0) {
55 nth_slice_specifier<K - 1>(rest...);
59template <
typename IndexType,
etl::size_t K,
typename... SliceSpecifiers>
60[[nodiscard]]
constexpr auto submdspan_first(SliceSpecifiers... slices) -> IndexType
62 auto sk = nth_slice_specifier<K>(slices...);
63 using Sk =
decltype(sk);
65 if constexpr (etl::convertible_to<Sk, IndexType>) {
66 return static_cast<IndexType
>(sk);
67 }
else if constexpr (index_pair_like<Sk, IndexType>) {
68 return static_cast<IndexType
>(get<0>(sk));
69 }
else if constexpr (is_strided_slice<Sk>) {
70 return static_cast<IndexType
>(de_ice(sk.offset));
72 return static_cast<IndexType
>(0);
76template <
etl::size_t K,
typename Extents,
typename... SliceSpecifiers>
77[[nodiscard]]
constexpr auto submdspan_last(Extents
const& src, SliceSpecifiers... slices)
79 auto sk = nth_slice_specifier<K>(slices...);
80 using Sk =
decltype(sk);
81 using IndexType =
typename Extents::index_type;
83 if constexpr (etl::convertible_to<Sk, IndexType>) {
84 return static_cast<IndexType
>(de_ice(sk)) + IndexType(1);
85 }
else if constexpr (index_pair_like<Sk, IndexType>) {
86 return static_cast<IndexType
>(get<1>(sk));
87 }
else if constexpr (is_strided_slice<Sk>) {
88 return static_cast<IndexType
>(de_ice(sk.offset) + de_ice(sk.extent));
90 return static_cast<IndexType
>(src.extent(K));
auto val(pin_number pin) -> etl::uint16_t
Definition gpio.hpp:37
constexpr bool is_integral_v
Definition is_integral.hpp:28
typename remove_const< T >::type remove_const_t
Definition remove_const.hpp:23
constexpr bool is_same_v
Definition is_same.hpp:11
integral_constant< bool, B > bool_constant
Definition bool_constant.hpp:11
TETL_BUILTIN_SIZET size_t
etl::size_t is the unsigned integer type of the result of the sizeof operator.
Definition size_t.hpp:14