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/is_valid_submdspan_slice_type_for.hpp"
11#include "arene/base/mdspan/detail/map_rank.hpp"
12#include "arene/base/mdspan/extents.hpp"
13#include "arene/base/mdspan/full_extent.hpp"
14#include "arene/base/mdspan/slice.hpp"
15#include "arene/base/stdlib_choice/cstddef.hpp"
16#include "arene/base/stdlib_choice/integer_sequence.hpp"
17#include "arene/base/type_list/at.hpp"
18#include "arene/base/type_list/type_list.hpp"
19#include "arene/base/type_traits/all_of.hpp"
20
21// parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
22// parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
23
24namespace arene {
25namespace base {
26namespace submdspan_subextents_type_detail {
27
28// parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: Used by
29// 'submdspan_subextents_type_impl' in this same header"
30
31/// @brief determines the static extent of a slice
32/// @param e_k static extent of the source mdspan
33/// @return the static extent @c e_k for a full_extent_t slice
34static constexpr auto subextents_static_extent_for(std::size_t const e_k, full_extent_t const&) noexcept
35 -> std::size_t {
36 return e_k;
37}
38
39/// @brief determines the static extent of an extent_slice
40/// @tparam Offset extent_slice offset type
41/// @tparam Extent extent_slice extent type
42/// @tparam Stride extent_slice stride type
43/// @return maybe-static-ext<Extent>
44template <class Offset, class Extent, class Stride>
45static constexpr auto subextents_static_extent_for( //
46 std::size_t, //
47 extent_slice<Offset, Extent, Stride> const& //
48) noexcept -> std::size_t {
49 return mdspan_detail::deduced_static_extent_v<Extent>;
50}
51
52// parasoft-end-suppress AUTOSAR-A0_1_3-a
53
54/// @brief implementation helper for @c submdspan_subextents_type
55/// @tparam Extents specialization of extents
56/// @tparam CanonicalSliceSpecifiers canonical slice specifier types
57/// Undefined primary template.
58template <class Extents, class... CanonicalSliceSpecifiers>
59class submdspan_subextents_type_impl;
60
61/// @brief implementation helper for @c submdspan_subextents_type
62/// @tparam IndexType extents index type
63/// @tparam Extents parameter pack of static extent values
64/// @tparam CanonicalSliceSpecifiers canonical slice specifier types
65///
66template <class IndexType, std::size_t... Extents, class... CanonicalSliceSpecifiers>
67class submdspan_subextents_type_impl<extents<IndexType, Extents...>, CanonicalSliceSpecifiers...> {
68 static_assert(
69 all_of_v<mdspan_detail::is_valid_submdspan_slice_type_for_v<CanonicalSliceSpecifiers, Extents>...>,
70 "each type in 'SliceSpecifiers' must be a valid 'submdspan' slice type for the associated extent"
71 );
72
73 // parasoft-begin-suppress CERT_CPP-DCL56-a "False positive: variables are initialized"
74 /// @brief mapping of indices from the sliced extents back to the source extents
75 static constexpr auto const& inverse_map_rank = mdspan_detail::inverse_map_rank<CanonicalSliceSpecifiers...>;
76 // parasoft-end-suppress CERT_CPP-DCL56-a
77
78 /// @brief helper to determine the sliced extents type
79 /// @tparam Is parameter pack of indices corresponding to the (reduced) rank after slicing
80 /// @return sliced extents type
81 template <std::size_t... Is>
82 static auto impl(std::index_sequence<Is...>) -> extents<
83 IndexType,
84 subextents_static_extent_for(
85 extents<IndexType, Extents...>::static_extent(inverse_map_rank[Is]),
86 type_lists::at_t<type_list<CanonicalSliceSpecifiers...>, inverse_map_rank[Is]>{}
87 )...>;
88
89 public:
90 /// @brief sliced extents type
91 using type = decltype(impl(std::make_index_sequence<inverse_map_rank.size()>{}));
92};
93
94} // namespace submdspan_subextents_type_detail
95
96/// @brief determines the subextents type from an extents type and slice specifiers
97/// @tparam Extents specialization of extents type
98/// @tparam SliceSpecifiers parameter pack specifying the subset of each rank in
99/// @c Extents
100///
101/// Provides the member typedef @c type which is a specialization of @c extents
102/// after rank reducing @c Extents and determining the static subset of each
103/// remaining rank in @c Extents.
104///
105/// @note Mandates <br>
106/// * each type @c S in @c SliceSpecifiers... is a valid submdspan slice for
107/// @c Extents::index_type
108/// * the canonical form of each @c S in @c SliceSpecifiers... is a valid
109/// submdspan slice type for associated static extent of @c Extents
110template <class Extents, class... SliceSpecifiers>
115
116/// @brief determines the subextents type from an extents type and slice specifiers
117/// @tparam Extents specialization of extents type
118/// @tparam SliceSpecifiers parameter pack specifying the subset of each rank in
119/// @c Extents
120template <class Extents, class... SliceSpecifiers>
121using submdspan_subextents_type_t = typename submdspan_subextents_type<Extents, SliceSpecifiers...>::type;
122
123} // namespace base
124} // namespace arene
125
126#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:114
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10