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
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"
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,
40 > = [] {
41 static_assert( //
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,
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,
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>
102extern constexpr bool is_submdspan_slice_v = is_submdspan_slice_detail::is_submdspan_slice_v<IndexType, Slice>;
103
104} // namespace base
105} // namespace arene
106
107#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_IS_SUBMDSPAN_SLICE_HPP_
static constexpr value_type value
Definition integral_constant.hpp:34
Provides the is_tuple_like_v<T> and is_pair_like_v<T> traits.
Definition accumulate.hpp:37
constexpr bool is_submdspan_slice_v
helper trait to check if a type is a submdspan slice type
constexpr bool is_instantiation_of_v
Definition is_instantiation_of.hpp:16
constexpr bool is_pair_like_v
Type trait to check if a type implements the tuple protocol and has a std::tuple_size of 2.
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41