Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_layout_mapping.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_LAYOUT_MAPPING_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_IS_LAYOUT_MAPPING_HPP_
7
8// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
9#include "arene/base/constraints/constraints.hpp"
10#include "arene/base/mdspan/extents.hpp"
11#include "arene/base/stdlib_choice/cstdint.hpp"
12#include "arene/base/stdlib_choice/declval.hpp"
13#include "arene/base/stdlib_choice/enable_if.hpp"
14#include "arene/base/stdlib_choice/integer_sequence.hpp"
15#include "arene/base/stdlib_choice/is_move_assignable.hpp"
16#include "arene/base/stdlib_choice/is_move_constructible.hpp"
17#include "arene/base/stdlib_choice/is_same.hpp"
18#include "arene/base/type_traits/comparison_traits.hpp"
19#include "arene/base/type_traits/is_copyable.hpp"
20#include "arene/base/type_traits/is_invocable.hpp"
21#include "arene/base/type_traits/is_swappable.hpp"
22// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
23
24namespace arene {
25namespace base {
26
27namespace is_layout_mapping_detail {
28
29/// @brief Helper trait to indicate if the given type is invocable with the number of index parameters equal to the rank
30/// of @c T::extents_type returning an instance of @c T::index_type
31///
32/// The value is @c true if @c T is invocable in this way, @c false otherwise
33/// @tparam T The type being checked
34template <
35 typename T,
36 typename = std::make_integer_sequence<typename T::index_type, T::extents_type::rank()>,
37 typename = constraints<>>
38extern constexpr bool is_invocable_with_extents_indices_v = false;
39
40/// @brief Helper trait to indicate if the given type is invocable with the number of index parameters equal to the rank
41/// of @c T::extents_type returning an instance of @c T::index_type
42///
43/// The value is @c true if @c T is invocable in this way, @c false otherwise
44/// @tparam T The type being checked
45/// @tparam IndexType the index type of the extents
46/// @tparam Indices A list of @c T::extents_type::rank() sample values of the @c IndexType
47template <typename T, typename IndexType, IndexType... Indices>
48extern constexpr bool is_invocable_with_extents_indices_v<
49 T,
50 std::integer_sequence<IndexType, Indices...>,
51 constraints<std::enable_if_t<is_invocable_v<T const&, decltype(Indices)...>>>> =
52 std::is_same<invoke_result_t<T const&, decltype(Indices)...>, IndexType>::value;
53
54/// @brief Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
55/// - It must be copy constructible, and copy assignable
56/// - It must be nothrow-move-constructible and nothrow-move-assignable
57/// - It must be nothrow-swappable
58/// - It must be equality comparable
59/// - It must have the type aliases:
60/// - @c T::extents_type must be an instance of @c extents
61/// - @c T::index_type must be an alias for @c T::extents_type::index_type
62/// - @c rank_type must be an alias for @c T::extents_type::rank_type
63/// - @c layout_type must exist
64/// - It must have the @c const member functions:
65/// - @c extents() must return an instance of @c T::extents_type
66/// - @c required_span_size() must return an instance of @c T::index_type
67/// - @c is_unique() must return @c bool
68/// - @c is_exhaustive() must return @c bool
69/// - @c is_strided() must return @c bool
70/// - It must have the @c static member functions:
71/// - @c is_always_unique() must return @c bool
72/// - @c is_always_exhaustive() must return @c bool
73/// - @c is_always_strided() must return @c bool
74/// - It must be invocable with @c T::extents_type::rank() indices of type @c T::index_type returning an instance of @c
75/// T::index_type
76///
77/// The value is @c true if @c T has all these properties, @c false otherwise
78/// @tparam T The type being checked
79template <typename T, typename = constraints<>>
80extern constexpr bool is_basic_layout_mapping_v = false;
81
82/// @brief Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
83/// - It must be copy constructible, and copy assignable
84/// - It must be nothrow-move-constructible and nothrow-move-assignable
85/// - It must be nothrow-swappable
86/// - It must be equality comparable
87/// - It must have the type aliases:
88/// - @c T::extents_type must be an instance of @c extents
89/// - @c T::index_type must be an alias for @c T::extents_type::index_type
90/// - @c rank_type must be an alias for @c T::extents_type::rank_type
91/// - @c layout_type must exist
92/// - It must have the @c const member functions:
93/// - @c extents() must return an instance of @c T::extents_type
94/// - @c required_span_size() must return an instance of @c T::index_type
95/// - @c is_unique() must return @c bool
96/// - @c is_exhaustive() must return @c bool
97/// - @c is_strided() must return @c bool
98/// - It must have the @c static member functions:
99/// - @c is_always_unique() must be a constant expression returning @c bool
100/// - @c is_always_exhaustive() must be a constant expression returning @c bool
101/// - @c is_always_strided() must be a constant expression returning @c bool
102/// - It must be invocable with @c T::extents_type::rank() indices of type @c T::index_type returning an instance of @c
103/// T::index_type
104///
105/// The value is @c true if @c T has all these properties, @c false otherwise
106/// @tparam T The type being checked
107template <typename T>
108extern constexpr bool is_basic_layout_mapping_v<
109 T,
110 constraints<
111 typename T::extents_type,
112 typename T::index_type,
113 typename T::rank_type,
114 typename T::layout_type,
115 decltype(std::declval<T const&>().extents()),
116 decltype(std::declval<T const&>().required_span_size()),
117 decltype(std::declval<T const&>().is_unique()),
118 decltype(std::declval<T const&>().is_exhaustive()),
119 decltype(std::declval<T const&>().is_strided()),
120 decltype(T::is_always_unique()),
121 decltype(T::is_always_strided()),
122 decltype(T::is_always_exhaustive()),
123 std::enable_if_t<(static_cast<void>(T::is_always_unique()), true)>,
124 std::enable_if_t<(static_cast<void>(T::is_always_strided()), true)>,
125 std::enable_if_t<(static_cast<void>(T::is_always_exhaustive()), true)>,
126 std::enable_if_t<is_extents_v<typename T::extents_type>>,
127 std::enable_if_t<is_copyable_v<T>>,
128 std::enable_if_t<std::is_nothrow_move_constructible<T>::value>,
129 std::enable_if_t<std::is_nothrow_move_assignable<T>::value>,
130 std::enable_if_t<is_nothrow_swappable_v<T>>,
131 std::enable_if_t<is_equality_comparable_v<T>>>> =
132 std::is_same<typename T::index_type, typename T::extents_type::index_type>::value &&
133 std::is_same<typename T::rank_type, typename T::extents_type::rank_type>::value &&
134 std::is_same<decltype(std::declval<T const&>().extents()), typename T::extents_type const&>::value &&
135 std::is_same<decltype(std::declval<T const&>().required_span_size()), typename T::index_type>::value &&
136 std::is_same<decltype(std::declval<T const&>().is_unique()), bool>::value &&
137 std::is_same<decltype(std::declval<T const&>().is_exhaustive()), bool>::value &&
138 std::is_same<decltype(std::declval<T const&>().is_strided()), bool>::value &&
139 std::is_same<decltype(T::is_always_unique()), bool>::value &&
140 std::is_same<decltype(T::is_always_exhaustive()), bool>::value &&
141 std::is_same<decltype(T::is_always_strided()), bool>::value && is_invocable_with_extents_indices_v<T>;
142
143/// @brief Sample extents type for checking layout mapping policy
144// NOLINTNEXTLINE(readability-magic-numbers)
145using sample_extents_1 = dextents<std::int32_t, 5>;
146/// @brief Sample extents type for checking layout mapping policy
147using sample_extents_2 = extents<std::uint16_t, 1, 2, 3, 4>;
148
149/// @brief Helper trait to check if @c T is a valid layout mapping policy
150///
151/// A valid layout mapping policy must have a @c template member @c mapping such that @c T::mapping<some_extent> is a
152/// valid layout mapping, such that @c T::mapping<some_extent>::extents_type is @c some_extent and @c
153/// T::mapping<some_extent>::layout_type is @c T
154///
155/// The value is @c true if @c T has all these properties, @c false otherwise
156/// @tparam T The type being checked
157template <typename T, typename = constraints<>>
158extern constexpr bool is_layout_mapping_policy_v = false;
159
160/// @brief Helper trait to check if @c T is a valid layout mapping policy
161///
162/// A valid layout mapping policy must have a @c template member @c mapping such that @c T::mapping<some_extent> is a
163/// valid layout mapping, such that @c T::mapping<some_extent>::extents_type is @c some_extent and @c
164/// T::mapping<some_extent>::layout_type is @c T
165///
166/// The value is @c true if @c T has all these properties, @c false otherwise
167/// @tparam T The type being checked
168template <typename T>
169extern constexpr bool is_layout_mapping_policy_v<
170 T,
171 constraints<
172 std::enable_if_t<is_basic_layout_mapping_v<typename T::template mapping<sample_extents_1>>>,
173 std::enable_if_t<
174 std::is_same<typename T::template mapping<sample_extents_1>::extents_type, sample_extents_1>::value>,
175 std::enable_if_t<std::is_same<typename T::template mapping<sample_extents_1>::layout_type, T>::value>,
176 std::enable_if_t<is_basic_layout_mapping_v<typename T::template mapping<sample_extents_2>>>,
177 std::enable_if_t<
178 std::is_same<typename T::template mapping<sample_extents_2>::extents_type, sample_extents_2>::value>,
179 std::enable_if_t<std::is_same<typename T::template mapping<sample_extents_2>::layout_type, T>::value>>> = true;
180
181/// @brief Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
182/// - It must be copy constructible, and copy assignable
183/// - It must be nothrow-move-constructible and nothrow-move-assignable
184/// - It must be nothrow-swappable
185/// - It must be equality comparable
186/// - It must have the type aliases
187/// - @c T::extents_type must be an instance of @c extents
188/// - @c T::index_type must be an alias for @c T::extents_type::index_type
189/// - @c T::rank_type must be an alias for @c T::extents_type::rank_type
190/// - @c T::layout_type must be a valid layout mapping policy for @c T such that @c
191/// T::layout_type::mapping<T::extents_type> is @c T
192/// - It must have the @c const member functions:
193/// - @c extents() must return an instance of @c T::extents_type
194/// - @c required_span_size() must return an instance of @c T::index_type
195/// - @c is_unique() must return @c bool
196/// - @c is_exhaustive() must return @c bool
197/// - @c is_strided() must return @c bool
198/// - It must have the @c static member functions:
199/// - @c is_always_unique() must return @c bool
200/// - @c is_always_exhaustive() must return @c bool
201/// - @c is_always_strided() must return @c bool
202/// - It must be invocable with @c T::extents_type::rank() indices of type @c T::index_type returning an instance of @c
203/// T::index_type
204///
205/// The value is @c true if @c T has all these properties, @c false otherwise
206/// @tparam T The type being checked
207template <typename T, typename = constraints<>>
208extern constexpr bool is_layout_mapping_v = false;
209
210/// @brief Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
211/// - It must be copy constructible, and copy assignable
212/// - It must be nothrow-move-constructible and nothrow-move-assignable
213/// - It must be nothrow-swappable
214/// - It must be equality comparable
215/// - It must have the type aliases:
216/// - @c T::extents_type must be an instance of @c extents
217/// - @c T::index_type must be an alias for @c T::extents_type::index_type
218/// - @c T::rank_type must be an alias for @c T::extents_type::rank_type
219/// - @c T::layout_type must be a valid layout mapping policy for @c T such that @c
220/// T::layout_type::mapping<T::extents_type> is @c T
221/// - It must have the @c const member functions:
222/// - @c extents() must return an instance of @c T::extents_type
223/// - @c required_span_size() must return an instance of @c T::index_type
224/// - @c is_unique() must return @c bool
225/// - @c is_exhaustive() must return @c bool
226/// - @c is_strided() must return @c bool
227/// - It must have the @c static member functions:
228/// - @c is_always_unique() must return @c bool
229/// - @c is_always_exhaustive() must return @c bool
230/// - @c is_always_strided() must return @c bool
231/// - It must be invocable with @c T::extents_type::rank() indices of type @c T::index_type returning an instance of @c
232/// T::index_type
233///
234/// The value is @c true if @c T has all these properties, @c false otherwise
235/// @tparam T The type being checked
236template <typename T>
237extern constexpr bool is_layout_mapping_v<
238 T,
239 constraints<
240 std::enable_if_t<is_basic_layout_mapping_v<T>>,
241 std::enable_if_t<
242 std::is_same<typename T::layout_type::template mapping<typename T::extents_type>, T>::value>>> =
243 is_layout_mapping_policy_v<typename T::layout_type>;
244
245} // namespace is_layout_mapping_detail
246
247/// @brief Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
248/// - It must be copy constructible, and copy assignable
249/// - It must be nothrow-move-constructible and nothrow-move-assignable
250/// - It must be nothrow-swappable
251/// - It must be equality comparable
252/// - It must have the type aliases:
253/// - @c T::extents_type must be an instance of @c extents
254/// - @c T::index_type must be an alias for @c T::extents_type::index_type
255/// - @c T::rank_type must be an alias for @c T::extents_type::rank_type
256/// - @c T::layout_type must be a valid layout mapping policy for @c T such that @c
257/// T::layout_type::mapping<T::extents_type> is @c T
258/// - It must have the @c const member functions:
259/// - @c extents() must return an instance of @c T::extents_type
260/// - @c required_span_size() must return an instance of @c T::index_type
261/// - @c is_unique() must return @c bool
262/// - @c is_exhaustive() must return @c bool
263/// - @c is_strided() must return @c bool
264/// - It must have the @c static member functions:
265/// - @c is_always_unique() must return @c bool
266/// - @c is_always_exhaustive() must return @c bool
267/// - @c is_always_strided() must return @c bool
268/// - It must be invocable with @c T::extents_type::rank() indices of type @c T::index_type returning an instance of @c
269/// T::index_type
270///
271/// The value is @c true if @c T has all these properties, @c false otherwise
272/// @tparam T The type being checked
273template <typename T>
275
276/// @brief Helper trait to check if @c T is a valid layout mapping policy
277///
278/// A valid layout mapping policy must have a @c template member @c mapping such that @c T::mapping<some_extent> is a
279/// valid layout mapping, such that @c T::mapping<some_extent>::extents_type is @c some_extent and @c
280/// T::mapping<some_extent>::layout_type is @c T
281///
282/// The value is @c true if @c T has all these properties, @c false otherwise
283/// @tparam T The type being checked
284template <typename T>
286
287} // namespace base
288} // namespace arene
289
290#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_IS_LAYOUT_MAPPING_HPP_
Definition array_exceptions_disabled.cpp:11
constexpr bool is_layout_mapping_v
Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
constexpr bool is_layout_mapping_policy_v
Helper trait to check if T is a valid layout mapping policy.
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10