4#ifndef TETL_MDSPAN_INTEGRAL_CONSTANT_LIKE_HPP
5#define TETL_MDSPAN_INTEGRAL_CONSTANT_LIKE_HPP
7#include <etl/_concepts/convertible_to.hpp>
8#include <etl/_cstddef/size_t.hpp>
9#include <etl/_mdspan/strided_slice.hpp>
10#include <etl/_type_traits/always_false.hpp>
11#include <etl/_type_traits/bool_constant.hpp>
12#include <etl/_type_traits/is_integral.hpp>
13#include <etl/_type_traits/is_same.hpp>
14#include <etl/_type_traits/remove_const.hpp>
16namespace etl::detail {
19concept pair_like =
true;
21template <
typename T,
typename IndexType>
22concept index_pair_like =
24 and etl::convertible_to<etl::tuple_element_t<0, T>, IndexType>
25 and etl::convertible_to<etl::tuple_element_t<1, T>, IndexType>
29concept integral_constant_like =
30 etl::is_integral_v<
decltype(T::value)>
31 and not etl::is_same_v<
bool,
etl::remove_const_t<
decltype(T::value)>>
32 and etl::convertible_to<T,
decltype(T::value)>
34 and etl::bool_constant<T() == T::value>::value
35 and etl::bool_constant<
static_cast<
decltype(T::value)>(T()) == T::value>::value
39[[nodiscard]]
constexpr auto de_ice(T val) -> T
44template <integral_constant_like T>
45[[nodiscard]]
constexpr auto de_ice(T )
50template <
etl::size_t K>
51[[nodiscard]]
constexpr auto nth_slice_specifier(
auto first,
auto... rest)
53 if constexpr (K == 0) {
56 nth_slice_specifier<K - 1>(rest...);
60template <
typename IndexType,
etl::size_t K,
typename... SliceSpecifiers>
61[[nodiscard]]
constexpr auto submdspan_first(SliceSpecifiers... slices) -> IndexType
63 auto sk = nth_slice_specifier<K>(slices...);
64 using Sk =
decltype(sk);
66 if constexpr (
etl::convertible_to<Sk, IndexType>) {
67 return static_cast<IndexType>(sk);
68 }
else if constexpr (index_pair_like<Sk, IndexType>) {
69 return static_cast<IndexType>(get<0>(sk));
70 }
else if constexpr (is_strided_slice<Sk>) {
71 return static_cast<IndexType>(de_ice(sk.offset));
73 return static_cast<IndexType>(0);
77template <
etl::size_t K,
typename Extents,
typename... SliceSpecifiers>
78[[nodiscard]]
constexpr auto submdspan_last(Extents
const& src, SliceSpecifiers... slices)
80 auto sk = nth_slice_specifier<K>(slices...);
81 using Sk =
decltype(sk);
82 using IndexType =
typename Extents::index_type;
84 if constexpr (
etl::convertible_to<Sk, IndexType>) {
85 return static_cast<IndexType>(de_ice(sk)) + IndexType(1);
86 }
else if constexpr (index_pair_like<Sk, IndexType>) {
87 return static_cast<IndexType>(get<1>(sk));
88 }
else if constexpr (is_strided_slice<Sk>) {
89 return static_cast<IndexType>(de_ice(sk.offset) + de_ice(sk.extent));
91 return static_cast<IndexType>(src.extent(K));
Definition adjacent_find.hpp:9