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"
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"
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,
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)>,
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 Detection helper to bind a one-parameter member template without instantiating its body
144/// @tparam T The one-parameter @c mapping member template being checked
145template <template <typename> class T>
146struct mapping_template_check {};
147
148/// @brief Substitution alias used to detect that @c T exposes a one-parameter member template named @c mapping .
149/// @tparam T The type being checked
150template <typename T>
151using uses_mapping = mapping_template_check<T::template mapping>;
152
153/// @brief Helper trait to check that @c T is shaped like a layout mapping policy
154/// @tparam T The type being checked
155template <typename T>
156extern constexpr bool is_layout_mapping_policy_v = substitution_succeeds<uses_mapping, T>;
157
158/// @brief Helper trait to check if @c T is a valid layout mapping policy for the concrete extents type @c E .
159/// @tparam T The type being checked
160/// @tparam E The concrete extents specialization the policy must accept
161template <typename T, typename E, typename = constraints<>>
162extern constexpr bool is_layout_mapping_policy_for_extents_v = false;
163
164/// @brief Helper trait to check if @c T is a valid layout mapping policy for the concrete extents type @c E .
165/// @tparam T The type being checked
166/// @tparam E The concrete extents specialization the policy must accept
167template <typename T, typename E>
168extern constexpr bool is_layout_mapping_policy_for_extents_v<
169 T,
170 E,
175 std::enable_if_t<std::is_same<typename T::template mapping<E>::extents_type, E>::value>,
176 std::enable_if_t<std::is_same<typename T::template mapping<E>::layout_type, T>::value>>> = true;
177
178/// @brief Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
179/// - It must be copy constructible, and copy assignable
180/// - It must be nothrow-move-constructible and nothrow-move-assignable
181/// - It must be nothrow-swappable
182/// - It must be equality comparable
183/// - It must have the type aliases
184/// - @c T::extents_type must be an instance of @c extents
185/// - @c T::index_type must be an alias for @c T::extents_type::index_type
186/// - @c T::rank_type must be an alias for @c T::extents_type::rank_type
187/// - @c T::layout_type must be a valid layout mapping policy for @c T such that @c
188/// T::layout_type::mapping<T::extents_type> is @c T
189/// - It must have the @c const member functions:
190/// - @c extents() must return an instance of @c T::extents_type
191/// - @c required_span_size() must return an instance of @c T::index_type
192/// - @c is_unique() must return @c bool
193/// - @c is_exhaustive() must return @c bool
194/// - @c is_strided() must return @c bool
195/// - It must have the @c static member functions:
196/// - @c is_always_unique() must return @c bool
197/// - @c is_always_exhaustive() must return @c bool
198/// - @c is_always_strided() must return @c bool
199/// - It must be invocable with @c T::extents_type::rank() indices of type @c T::index_type returning an instance of @c
200/// T::index_type
201///
202/// The value is @c true if @c T has all these properties, @c false otherwise
203/// @tparam T The type being checked
204template <typename T, typename = constraints<>>
205extern constexpr bool is_layout_mapping_v = false;
206
207/// @brief Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
208/// - It must be copy constructible, and copy assignable
209/// - It must be nothrow-move-constructible and nothrow-move-assignable
210/// - It must be nothrow-swappable
211/// - It must be equality comparable
212/// - It must have the type aliases:
213/// - @c T::extents_type must be an instance of @c extents
214/// - @c T::index_type must be an alias for @c T::extents_type::index_type
215/// - @c T::rank_type must be an alias for @c T::extents_type::rank_type
216/// - @c T::layout_type must be a valid layout mapping policy for @c T such that @c
217/// T::layout_type::mapping<T::extents_type> is @c T
218/// - It must have the @c const member functions:
219/// - @c extents() must return an instance of @c T::extents_type
220/// - @c required_span_size() must return an instance of @c T::index_type
221/// - @c is_unique() must return @c bool
222/// - @c is_exhaustive() must return @c bool
223/// - @c is_strided() must return @c bool
224/// - It must have the @c static member functions:
225/// - @c is_always_unique() must return @c bool
226/// - @c is_always_exhaustive() must return @c bool
227/// - @c is_always_strided() must return @c bool
228/// - It must be invocable with @c T::extents_type::rank() indices of type @c T::index_type returning an instance of @c
229/// T::index_type
230///
231/// The value is @c true if @c T has all these properties, @c false otherwise
232/// @tparam T The type being checked
233template <typename T>
234extern constexpr bool is_layout_mapping_v<
235 T,
239 std::is_same<typename T::layout_type::template mapping<typename T::extents_type>, T>::value>>> =
240 is_layout_mapping_policy_for_extents_v<typename T::layout_type, typename T::extents_type>;
241
242} // namespace is_layout_mapping_detail
243
244/// @brief Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
245/// - It must be copy constructible, and copy assignable
246/// - It must be nothrow-move-constructible and nothrow-move-assignable
247/// - It must be nothrow-swappable
248/// - It must be equality comparable
249/// - It must have the type aliases:
250/// - @c T::extents_type must be an instance of @c extents
251/// - @c T::index_type must be an alias for @c T::extents_type::index_type
252/// - @c T::rank_type must be an alias for @c T::extents_type::rank_type
253/// - @c T::layout_type must be a valid layout mapping policy for @c T such that @c
254/// T::layout_type::mapping<T::extents_type> is @c T
255/// - It must have the @c const member functions:
256/// - @c extents() must return an instance of @c T::extents_type
257/// - @c required_span_size() must return an instance of @c T::index_type
258/// - @c is_unique() must return @c bool
259/// - @c is_exhaustive() must return @c bool
260/// - @c is_strided() must return @c bool
261/// - It must have the @c static member functions:
262/// - @c is_always_unique() must return @c bool
263/// - @c is_always_exhaustive() must return @c bool
264/// - @c is_always_strided() must return @c bool
265/// - It must be invocable with @c T::extents_type::rank() indices of type @c T::index_type returning an instance of @c
266/// T::index_type
267///
268/// The value is @c true if @c T has all these properties, @c false otherwise
269/// @tparam T The type being checked
270/// @tparam Enable SFINAE hook used by specializations
271template <typename T, typename Enable = void>
272extern constexpr bool is_layout_mapping_v = is_layout_mapping_detail::is_layout_mapping_v<T>;
273
274/// @brief Helper trait to check if @c T is a valid layout mapping policy
275///
276/// A valid layout mapping policy must have a @c template member @c mapping
277///
278/// The value is @c true if @c T has all these properties, @c false otherwise
279/// @tparam T The type being checked
280template <typename T>
281extern constexpr bool is_layout_mapping_policy_v = is_layout_mapping_detail::is_layout_mapping_policy_v<T>;
282
283/// @brief Helper trait to check if @c T is a valid layout mapping policy for the extents @c E
284///
285/// A valid layout mapping policy must have a @c template member @c mapping such that @c T::mapping<E> is a
286/// valid layout mapping
287///
288/// The value is @c true if @c T has all these properties, @c false otherwise
289/// @tparam T The type being checked
290/// @tparam E The extents to use to check
291template <typename T, typename E>
292extern constexpr bool is_layout_mapping_policy_for_extents_v =
293 is_layout_mapping_detail::is_layout_mapping_policy_for_extents_v<T, E>;
294
295} // namespace base
296} // namespace arene
297
298#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_IS_LAYOUT_MAPPING_HPP_
static constexpr value_type value
Definition integral_constant.hpp:34
Definition accumulate.hpp:37
constexpr bool is_nothrow_swappable_v
Trait query indicating if a type can be noexcept-swapped.
constexpr bool is_invocable_v
Determine if a functor type is invocable with the specified argument types.
constexpr bool substitution_succeeds
Determines if a template can be instantiated successfully, similar to C++20's requires clause.
typename invoke_result< Fn, Args... >::type invoke_result_t
The return type of a functor invoked with the specified arguments.
Definition is_invocable.hpp:271
constexpr bool is_copyable_v
Backport for the C++20 copyable concept.
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.
constexpr bool is_layout_mapping_policy_for_extents_v
Helper trait to check if T is a valid layout mapping policy for the extents E.
constexpr bool is_extents_v
Helper variable to check if a provided type is an instantiation of extents.
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
constexpr bool is_equality_comparable_v
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
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
typename integer_sequence_detail::make_integer_sequence< Type, Size >::type make_integer_sequence
Helper alias template to simplify creation of std::integer_sequence types with 0, 1,...
Definition integer_sequence.hpp:212