Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_submdspan_slice.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_IS_SUBMDSPAN_SLICE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_IS_SUBMDSPAN_SLICE_HPP_
7
8#include "arene/base/constraints/constraints.hpp"
9#include "arene/base/mdspan/full_extent.hpp"
10#include "arene/base/mdspan/slice.hpp"
11#include "arene/base/stdlib_choice/enable_if.hpp"
12#include "arene/base/stdlib_choice/is_convertible.hpp"
13#include "arene/base/stdlib_choice/is_integral.hpp"
14#include "arene/base/stdlib_choice/remove_reference.hpp"
15#include "arene/base/stdlib_choice/tuple_element.hpp"
16#include "arene/base/type_traits/is_instantiation_of.hpp"
17#include "arene/base/type_traits/is_tuple_like.hpp"
18
19namespace arene {
20namespace base {
21namespace is_submdspan_slice_detail {
22
23/// @brief implementation to check if a type is a submdspan slice type
24/// @tparam IndexType mdspan index type
25/// @tparam Slice potential submdspan slice type
26template <class IndexType, class Slice, class = constraints<>>
27extern constexpr bool is_submdspan_slice_v = false;
28
29/// @brief implementation to check if a type is a submdspan slice type
30/// @tparam IndexType mdspan index type
31/// @tparam Slice potential submdspan slice type
32///
33/// Specialization that creates a hard error if @c IndexType is not an integer.
34template <class IndexType, class Slice>
35extern constexpr bool is_submdspan_slice_v<
36 IndexType,
37 Slice,
38 constraints<std::enable_if_t< //
39 !std::is_integral<IndexType>::value>> //
40 > = [] {
41 static_assert( //
42 std::is_integral<IndexType>::value,
43 "'IndexType' must be an integer."
44 );
45 return false;
46}();
47
48/// @brief implementation to check if a type is a submdspan slice type
49/// @tparam IndexType mdspan index type
50/// @tparam Slice potential submdspan slice type
51///
52/// Specialization for everything except index-pair-likes. It is unnecessary to
53/// explicitly test convertibility of the @c extent_slice and @c range_slice
54/// type aliases.
55template <class IndexType, class Slice>
56extern constexpr bool is_submdspan_slice_v<
57 IndexType,
58 Slice,
59 constraints<std::enable_if_t<
60 std::is_integral<IndexType>::value && //
61 (std::is_convertible<Slice, full_extent_t>::value || //
62 std::is_convertible<Slice, IndexType>::value || //
63 is_instantiation_of_v<Slice, extent_slice> || //
64 is_instantiation_of_v<Slice, range_slice>)>>> = true;
65
66/// @brief implementation to check if a type is a submdspan slice type
67/// @tparam IndexType mdspan index type
68/// @tparam Slice potential submdspan slice type
69///
70/// Specialization for index-pair-likes.
71template <class IndexType, class Slice>
72extern constexpr bool is_submdspan_slice_v< //
73 IndexType,
74 Slice,
75 constraints<std::enable_if_t< //
76 std::is_integral<IndexType>::value && //
77 is_pair_like_v<Slice>>>> =
78 std::is_convertible<std::tuple_element_t<0, std::remove_reference_t<Slice>>, IndexType>::value &&
79 std::is_convertible<std::tuple_element_t<1, std::remove_reference_t<Slice>>, IndexType>::value;
80} // namespace is_submdspan_slice_detail
81
82/// @brief helper trait to check if a type is a submdspan slice type
83/// @tparam IndexType mdspan index type
84/// @tparam Slice potential submdspan slice type
85///
86/// Given a signed or unsigned integer type @c IndexType, a type @c Slice is a
87/// submdspan slice type for @c IndexType if at least one of the following holds:
88/// * <c> std::is_convertible<Slice, full_extent_t>::value </c> is @c true;
89/// * <c> std::is_convertible<Slice, IndexType>::value </c> is @c true;
90/// * @c Slice is a specialization of @c extent_slice and
91/// <c> std::is_convertible<X, IndexType>::value </c> is @c true
92/// for @c X denoting @c Slice::offset_type, @c Slice::extent_type, and
93/// @c Slice::stride_type;
94/// * @c Slice is a specialization of @c range_slice and
95/// <c> std::is_convertible<X, IndexType>::value </c> is @c true
96/// for @c X denoting @c Slice::first_type, @c Slice::last_type, and
97/// @c Slice::stride_type; or
98/// * @c Slice is pair-like, the "first type" of @c Slice is convertible to
99/// @c IndexType, and the "second type" of @c Slice is convertible to
100/// @c IndexType.
101template <class IndexType, class Slice>
103
104} // namespace base
105} // namespace arene
106
107#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_IS_SUBMDSPAN_SLICE_HPP_
Definition array_exceptions_disabled.cpp:11
constexpr bool is_submdspan_slice_v
helper trait to check if a type is a submdspan slice type
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10