Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
submdspan_subextents_type.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_SUBMDSPAN_SUBEXTENTS_TYPE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_SUBMDSPAN_SUBEXTENTS_TYPE_HPP_
7
8#include "arene/base/mdspan/detail/canonical_slice.hpp"
9#include "arene/base/mdspan/detail/deduced_static_extent.hpp"
10#include "arene/base/mdspan/detail/mandate_each_argtype_is_valid_submdspan_slice_type_for.hpp"
11#include "arene/base/mdspan/detail/map_rank.hpp"
15#include "arene/base/stdlib_choice/cstddef.hpp"
16#include "arene/base/stdlib_choice/integer_sequence.hpp"
19
20// parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
21// parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
22
23namespace arene {
24namespace base {
25namespace submdspan_subextents_type_detail {
26
27// parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: Used by
28// 'submdspan_subextents_type_impl' in this same header"
29
30/// @brief determines the static extent of a slice
31/// @param e_k static extent of the source mdspan
32/// @return the static extent @c e_k for a full_extent_t slice
33static constexpr auto subextents_static_extent_for(std::size_t const e_k, full_extent_t const&) noexcept
34 -> std::size_t {
35 return e_k;
36}
37
38/// @brief determines the static extent of an extent_slice
39/// @tparam Offset extent_slice offset type
40/// @tparam Extent extent_slice extent type
41/// @tparam Stride extent_slice stride type
42/// @return maybe-static-ext<Extent>
43template <class Offset, class Extent, class Stride>
44static constexpr auto subextents_static_extent_for( //
45 std::size_t, //
46 extent_slice<Offset, Extent, Stride> const& //
47) noexcept -> std::size_t {
48 return mdspan_detail::deduced_static_extent_v<Extent>;
49}
50
51// parasoft-end-suppress AUTOSAR-A0_1_3-a
52
53/// @brief implementation helper for @c submdspan_subextents_type
54/// @tparam Extents specialization of extents
55/// @tparam CanonicalSliceSpecifiers canonical slice specifier types
56/// Undefined primary template.
57template <class Extents, class... CanonicalSliceSpecifiers>
58class submdspan_subextents_type_impl;
59
60/// @brief implementation helper for @c submdspan_subextents_type
61/// @tparam IndexType extents index type
62/// @tparam Extents parameter pack of static extent values
63/// @tparam CanonicalSliceSpecifiers canonical slice specifier types
64///
65template <class IndexType, std::size_t... Extents, class... CanonicalSliceSpecifiers>
66class submdspan_subextents_type_impl<extents<IndexType, Extents...>, CanonicalSliceSpecifiers...> {
67 // Placing this call inside of a static assertion is one of the only ways to get GCC8 to instantiate the function.
68 static_assert(
69 (mdspan_detail::mandate_each_argtype_is_valid_submdspan_slice_type_for<IndexType, Extents...>(
70 type_list<CanonicalSliceSpecifiers...>{}
71 ),
72 true),
73 "This assertion always succeeds, but writing it causes other assertions to happen in the called function"
74 );
75
76 // parasoft-begin-suppress CERT_CPP-DCL56-a "False positive: variables are initialized"
77 /// @brief mapping of indices from the sliced extents back to the source extents
78 static constexpr auto const& inverse_map_rank = mdspan_detail::inverse_map_rank<CanonicalSliceSpecifiers...>;
79 // parasoft-end-suppress CERT_CPP-DCL56-a
80
81 /// @brief helper to determine the sliced extents type
82 /// @tparam Is parameter pack of indices corresponding to the (reduced) rank after slicing
83 /// @return sliced extents type
84 template <std::size_t... Is>
85 static auto impl(std::index_sequence<Is...>) -> extents<
86 IndexType,
87 subextents_static_extent_for(
88 extents<IndexType, Extents...>::static_extent(inverse_map_rank[Is]),
89 type_lists::at_t<type_list<CanonicalSliceSpecifiers...>, inverse_map_rank[Is]>{}
90 )...>;
91
92 public:
93 /// @brief sliced extents type
94 using type = decltype(impl(std::make_index_sequence<inverse_map_rank.size()>{}));
95};
96
97} // namespace submdspan_subextents_type_detail
98
99/// @brief determines the subextents type from an extents type and slice specifiers
100/// @tparam Extents specialization of extents type
101/// @tparam SliceSpecifiers parameter pack specifying the subset of each rank in
102/// @c Extents
103///
104/// Provides the member typedef @c type which is a specialization of @c extents
105/// after rank reducing @c Extents and determining the static subset of each
106/// remaining rank in @c Extents.
107///
108/// @note Mandates <br>
109/// * each type @c S in @c SliceSpecifiers... is a valid submdspan slice for
110/// @c Extents::index_type
111/// * the canonical form of each @c S in @c SliceSpecifiers... is a valid
112/// submdspan slice type for associated static extent of @c Extents
113template <class Extents, class... SliceSpecifiers>
115 : public submdspan_subextents_type_detail::submdspan_subextents_type_impl<
116 Extents,
117 mdspan_detail::canonical_slice_t<typename Extents::index_type, SliceSpecifiers>...> {};
118
119/// @brief determines the subextents type from an extents type and slice specifiers
120/// @tparam Extents specialization of extents type
121/// @tparam SliceSpecifiers parameter pack specifying the subset of each rank in
122/// @c Extents
123template <class Extents, class... SliceSpecifiers>
124using submdspan_subextents_type_t = typename submdspan_subextents_type<Extents, SliceSpecifiers...>::type;
125
126} // namespace base
127} // namespace arene
128
129#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_SUBMDSPAN_SUBEXTENTS_TYPE_HPP_
determines the subextents type from an extents type and slice specifiers
Definition submdspan_subextents_type.hpp:117
typename at< L0, Index >::type at_t
Get the n-th element from a type list.
Definition at.hpp:113
Definition accumulate.hpp:37
typename submdspan_subextents_type< Extents, SliceSpecifiers... >::type submdspan_subextents_type_t
determines the subextents type from an extents type and slice specifiers
Definition submdspan_subextents_type.hpp:124
Definition accumulate.hpp:36
make_integer_sequence< size_t, Size > make_index_sequence
A helper alias template for make_integer_sequence<size_t, Size>
Definition integer_sequence.hpp:224
integer_sequence< size_t, Ints... > index_sequence
A helper alias template for integer_sequence<size_t, Ints>
Definition integer_sequence.hpp:218
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29