Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
layout_stride.hpp
Go to the documentation of this file.
1// parasoft-suppress CERT_C-EXP37-a AUTOSAR-A2_8_1-a "False positive: there is no function named '()' here. Header
2// defines layout_stride types"
3
4// Copyright 2026, Toyota Motor Corporation
5//
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
8#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_LAYOUT_STRIDE_HPP_
9#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_LAYOUT_STRIDE_HPP_
10
11// IWYU pragma: no_include "arene/base/mdspan/layout.hpp"
12
13// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
17#include "arene/base/mdspan/detail/all_valid_submdspan_slice_types_for.hpp"
18#include "arene/base/mdspan/detail/layout_common.hpp" // IWYU pragma: keep
19#include "arene/base/mdspan/detail/strided_mapping_base.hpp" // IWYU pragma: keep
20#include "arene/base/mdspan/detail/submdspan_offset.hpp"
21#include "arene/base/mdspan/detail/submdspan_sub_strides.hpp"
27#include "arene/base/stdlib_choice/cstddef.hpp"
28#include "arene/base/stdlib_choice/enable_if.hpp"
29#include "arene/base/stdlib_choice/integer_sequence.hpp"
30#include "arene/base/stdlib_choice/integral_constant.hpp"
31#include "arene/base/stdlib_choice/is_constructible.hpp"
32#include "arene/base/stdlib_choice/is_convertible.hpp"
33#include "arene/base/stdlib_choice/is_same.hpp"
34#include "arene/base/stdlib_choice/move.hpp"
35#include "arene/base/stdlib_choice/numeric_limits.hpp"
37// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
38
39// parasoft-begin-suppress AUTOSAR-M2_10_1-a "Similar names permitted by M2-10-1 Permit #1"
40// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
41
42namespace arene {
43namespace base {
44namespace layout_detail {
45
46/// @brief Check that all of the given strides are positive, crashing with a precondition violation if not
47/// @tparam IndexType The index type used by @c strides
48/// @param strides The strides to check
49/// @pre All of the entries in @c strides are positive, else @c ARENE_PRECONDITION violation
50template <typename IndexType>
51constexpr auto precondition_all_strides_positive(span<IndexType const> strides) noexcept -> void {
52 for (auto const& stride : strides) {
53 ARENE_PRECONDITION(stride > IndexType{});
54 }
55}
56
57/// @brief Cast strides of one type to another
58/// @tparam OutputIndexType The type of the strides after casting
59/// @tparam InputIndexType The type of the strides before casting, deduced from @c strides
60/// @tparam Rank The rank (dimensionality) of the mapping, deduced from @c strides
61/// @param strides A set of strides using some original type, to be converted to @c OutputIndexType
62/// @return An array containing the input @c strides converted to @c OutputIndexType
63/// @pre All of the entries in @c strides are positive, else @c ARENE_PRECONDITION violation
64template <
65 typename OutputIndexType,
66 typename InputIndexType,
67 std::size_t Rank,
69constexpr auto stride_cast(span<InputIndexType const, Rank> strides) noexcept -> array<OutputIndexType, Rank> {
70 precondition_all_strides_positive<InputIndexType>(strides);
71
72 array<OutputIndexType, Rank> converted{};
73 for (std::size_t dim{}; dim < Rank; ++dim) {
74 converted[dim] = static_cast<OutputIndexType>(strides[dim]);
75 }
76 return converted;
77}
78
79/// @brief Cast strides of one type to another
80/// @tparam OutputIndexType The type of the strides after casting
81/// @tparam InputIndexType The type of the strides before casting, deduced from @c strides
82/// @tparam Rank The rank (dimensionality) of the mapping, deduced from @c strides
83/// @return An array containing the input @c strides converted to @c OutputIndexType
84/// @pre All of the entries in @c strides are positive, else @c ARENE_PRECONDITION violation
85template <
86 typename OutputIndexType,
87 typename InputIndexType,
88 std::size_t Rank,
90constexpr auto stride_cast(span<InputIndexType const, Rank>) noexcept -> array<OutputIndexType, Rank> {
91 return {};
92}
93
94/// @brief Type trait describing whether two strided mappings can be implicitly converted
95/// Conversion can be implicit if the extents are implicitly convertible and @c FromMapping is a known strided type.
96/// @tparam FromMapping The strided mapping from which the conversion is to be done
97/// @tparam ToMapping The strided mapping to which the conversion is to be done
98template <typename FromMapping, typename ToMapping, typename = constraints<>>
99class implicit_conversion_ok : public std::false_type {};
100
101/// @brief Type trait describing whether two strided mappings can be implicitly converted
102/// Conversion can be implicit if the extents are implicitly convertible and @c FromMapping is a known strided type.
103/// @tparam FromMapping The strided mapping from which the conversion is to be done
104/// @tparam ToMapping The strided mapping to which the conversion is to be done
105template <typename FromMapping, typename ToMapping>
106class implicit_conversion_ok<
107 FromMapping,
108 ToMapping,
109 constraints<typename FromMapping::extents_type, typename ToMapping::extents_type>>
110 : public std::integral_constant<
111 bool,
112 std::is_convertible<typename FromMapping::extents_type, typename ToMapping::extents_type>::value &&
113 (std::is_same<layout_left::mapping<typename FromMapping::extents_type>, FromMapping>::value ||
114 std::is_same<layout_right::mapping<typename FromMapping::extents_type>, FromMapping>::value ||
115 std::is_same<layout_stride::mapping<typename FromMapping::extents_type>, FromMapping>::value)> {};
116
117// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
118/// @brief Extract the strides from a mapping into an array using the mapping's public @c stride(dim) function
119/// @tparam The type of the mapping to extract from, deduced from @c mapping
120/// @param mapping The mapping to extract from
121/// @return An array containing the strides of @c mapping
122template <typename Mapping, constraints<std::enable_if_t<Mapping::extents_type::rank() != 0U>> = nullptr>
123constexpr auto extract_strides(Mapping const& mapping) noexcept
124 -> array<typename Mapping::index_type, Mapping::extents_type::rank()> {
125 array<typename Mapping::index_type, Mapping::extents_type::rank()> strides{};
126 for (typename Mapping::rank_type dim{}; dim < Mapping::extents_type::rank(); ++dim) {
127 strides[dim] = mapping.stride(dim);
128 }
129
130 return strides;
131}
132
133/// @brief Extract the strides from a mapping into an array using the mapping's public @c stride(dim) function
134/// @tparam The type of the mapping to extract from, deduced from @c mapping
135/// @return An array containing the strides of @c mapping
136/// @note This SFINAE overload is needed for GCC8 which thinks that 0-iteration for loops are not constexpr.
137template <typename Mapping, constraints<std::enable_if_t<Mapping::extents_type::rank() == 0U>> = nullptr>
138constexpr auto extract_strides(Mapping const&) noexcept -> array<typename Mapping::index_type, 0U> {
139 return {};
140}
141
142/// @brief Get the affine offset of the given mapping by checking the image of <c>(0, 0, ...)</c>
143/// @note Implements the exposition-only helper @c OFFSET(m) in [mdspan.layout.stride.expo].
144/// @tparam Mapping The type of the mapping to check
145/// @tparam Dims A pack of indices, one for each dimension of @c Mapping::extents_type
146/// @param mapping The mapping to check
147/// @return The constant offset of @c mapping (0 for all built-in layouts)
148template <typename Mapping, typename Mapping::rank_type... Dims>
149constexpr auto
150get_offset_of_mapping_impl(Mapping const& mapping, std::integer_sequence<typename Mapping::rank_type, Dims...>) noexcept
151 -> typename Mapping::index_type {
152 // If the output index space's size is 0, then the mapping's offset is 0 regardless of what the strides are set to.
153 if (mapping.required_span_size() == typename Mapping::index_type{}) {
154 return {};
155 }
156
157 // parasoft-begin-suppress AUTOSAR-M5_18_1-a "Comma operator avoids an expensive recursive iteration"
158 return mapping((static_cast<void>(Dims), typename Mapping::index_type{})...);
159 // parasoft-end-suppress AUTOSAR-M5_18_1-a
160}
161
162/// @brief Get the affine offset of the given mapping by checking the image of <c>(0, 0, ...)</c>
163/// @note Implements the exposition-only helper @c OFFSET(m) in [mdspan.layout.stride.expo].
164/// @tparam Mapping The type of the mapping to check
165/// @param mapping The mapping to check
166/// @return The constant offset of @c mapping (0 for all built-in layouts)
167template <typename Mapping, constraints<std::enable_if_t<Mapping::extents_type::rank() != 0U>> = nullptr>
168constexpr auto get_offset_of_mapping(Mapping const& mapping) noexcept -> typename Mapping::index_type {
169 return get_offset_of_mapping_impl(
170 mapping,
171 std::make_integer_sequence<typename Mapping::rank_type, Mapping::extents_type::rank()>{}
172 );
173}
174
175/// @brief Get the affine offset of the given mapping by checking the image of <c>(0, 0, ...)</c>
176/// @note Implements the exposition-only helper @c OFFSET(m) in [mdspan.layout.stride.expo].
177/// @tparam Mapping The type of the mapping to check
178/// @return The constant offset of @c mapping (0 for all built-in layouts)
179template <typename Mapping, constraints<std::enable_if_t<Mapping::extents_type::rank() == 0U>> = nullptr>
180constexpr auto get_offset_of_mapping(Mapping const&) noexcept -> typename Mapping::index_type {
181 return {};
182}
183// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
184
185} // namespace layout_detail
186
187// parasoft-begin-suppress AUTOSAR-A12_1_5-a "False positive: constructor preconditions differ so they can not delegate"
188// parasoft-begin-suppress AUTOSAR-A14_5_1-a "False positive: class is copyable without a user-defined copy constructor"
189/// @brief A mapping from a logical pack of indices into a single flat physical output index, using a strided algorithm
190/// @tparam The extents of the space used for this mapping; must be a specialization of @c extents
191template <class Extents>
192class layout_stride::mapping : private layout_detail::strided_mapping_base<Extents> {
193 private:
194 /// @brief Convenience typedef referring to the base strided mapping
195 using base_type = layout_detail::strided_mapping_base<Extents>;
196
197 public:
198 using typename base_type::extents_type;
199 using typename base_type::index_type;
200 using typename base_type::rank_type;
201 using typename base_type::size_type;
202 /// @brief The tag type of the layout used by this @c mapping
203 using layout_type = layout_stride;
204
205 private:
206 /// @brief obtain a check_bypasser passkey to skip precondition checks on
207 /// mapping construction
208 /// @return check_bypasser value
209 ///
210 /// @note This exists as a workaround for a GCC bug where access checking for
211 /// private constructors of friend classes can be incorrectly performed in
212 /// the caller's instantiation context rather than the definition context.
213 static constexpr auto passkey() noexcept -> layout_detail::check_bypasser { return layout_detail::check_bypasser{}; }
214
215 public:
216 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: Rule does not require all parameters to be named"
217 /// @brief Construct a mapping with the given strides, bypassing precondition checks
218 ///
219 /// @note This can only be called from classes which inherit from
220 /// layout_stride::mapping. It is used when slicing a layout_stride::mapping
221 /// if the slice arguments are valid, so that the preconditions on the public
222 /// constructors need not be re-checked.
223 ///
224 /// @param exts A set of extents to use for this mapping
225 /// @param strds A set of strides to use for this mapping
226 constexpr mapping(
227 extents_type const& exts,
228 array<index_type, extents_type::rank()> const& strds,
229 layout_detail::check_bypasser
230 ) noexcept
231 : base_type(exts, strds) {}
232 // parasoft-end-suppress CERT_C-EXP37-a
233
234 /// @brief Construct a default strided mapping for the given extents, which has the same layout as @c layout_right
235 constexpr mapping() noexcept
236 : base_type(extents_type{}, layout_detail::right_strides(extents_type{})) {
237 // Note: the precondition specified in [mdspan.layout.stride.cons] can not be violated so it's never checked.
238 }
239
240 /// @brief Construct a mapping with the given strides; they must be valid for a default-constructed @c extents_type
241 /// @tparam OtherIndexType The original index type used by <c>strds</c>; must be convertible to @c index_type
242 /// @param exts A set of extents to use for this mapping
243 /// @param strds A set of strides to use for this mapping
244 /// @pre All strides are positive when converted to <c>index_type</c>
245 /// @pre Size of the output index space is representable as <c>index_type</c>
246 /// @pre @c strds defines a unique (one-to-one) mapping from <c>exts</c>
247 template <
248 class OtherIndexType,
252 constexpr mapping(extents_type const& exts, span<OtherIndexType, extents_type::rank()> strds) noexcept
253 : base_type(exts, layout_detail::stride_cast<index_type>(strds)) {
254 // The representable precondition is checked here as a side-effect of 'required_span_size'.
255 index_type const span_size{this->required_span_size()};
256
257 // This is a necessary, but not sufficient check for uniqueness.
258 auto const extent_size = layout_detail::extent_product(exts);
259 ARENE_PRECONDITION(!extent_size.overflowed);
260 ARENE_PRECONDITION(span_size >= extent_size.value);
261 }
262
263 // parasoft-begin-suppress AUTOSAR-A12_1_1-a "False positive: this is a delegating constructor"
264 /// @brief Construct a mapping with the given strides; they must be valid for a default-constructed @c extents_type
265 /// @tparam OtherIndexType The original index type used by <c>strds</c>; must be convertible to @c index_type
266 /// @param exts A set of extents to use for this mapping
267 /// @param strds A set of strides to use for this mapping
268 /// @pre All strides are positive when converted to <c>index_type</c>, else @c ARENE_PRECONDITION violation
269 /// @pre Size of the output index space is representable as <c>index_type</c>, else @c ARENE_PRECONDITION violation
270 /// @pre @c strds defines a unique (one-to-one) mapping from <c>exts</c>, else @c ARENE_PRECONDITION violation
271 template <
272 class OtherIndexType,
276 constexpr mapping(extents_type const& exts, array<OtherIndexType, extents_type::rank()> const& strds) noexcept
277 : mapping(exts, span<OtherIndexType const, extents_type::rank()>(strds)) {}
278 // parasoft-end-suppress AUTOSAR-A12_1_1-a
279
280 /// @brief Construct a mapping from another strided mapping; implicit for certain known-safe mapping types
281 /// @tparam StridedLayoutMapping A layout mapping satisfying [mdspan.layout.reqmts] which is always strided and unique
282 /// @param other A mapping to convert
283 /// @pre All strides are positive when converted to <c>index_type</c>, else @c ARENE_PRECONDITION violation
284 /// @pre Size of the output index space is representable as <c>index_type</c>, else @c ARENE_PRECONDITION violation
285 /// @pre <c>other(0, 0, 0...) == 0</c>, else @c ARENE_PRECONDITION violation
286 template <
287 class StridedLayoutMapping,
291 std::enable_if_t<StridedLayoutMapping::is_always_strided()>,
292 std::enable_if_t<StridedLayoutMapping::is_always_unique()>,
294 // NOLINTNEXTLINE(hicpp-explicit-conversions) C++23 defines this as conditionally implicit
295 constexpr mapping(StridedLayoutMapping const& other) noexcept
296 : base_type(
297 extents_type(other.extents()),
298 layout_detail::stride_cast<index_type>(
299 span<typename StridedLayoutMapping::index_type const, StridedLayoutMapping::extents_type::rank()>(
300 layout_detail::extract_strides(other)
301 )
302 )
303 ) {
304 // None of the preconditions can be violated for the implicit version of this function. StridedLayoutMapping must be
305 // a known type and all standard layouts have zero offset, positive strides, and in-bounds required_span_size.
306 // The extents_type must also be implicitly convertible, so casting required_span_size can not go OOB either.
307 }
308
309 /// @brief Construct a mapping from another strided mapping; implicit for certain known-safe mapping types
310 /// @tparam StridedLayoutMapping A layout mapping satisfying [mdspan.layout.reqmts] which is always strided and unique
311 /// @param other A mapping to convert
312 /// @pre All strides are positive when converted to <c>index_type</c>, else @c ARENE_PRECONDITION violation
313 /// @pre Size of the output index space is representable as <c>index_type</c>, else @c ARENE_PRECONDITION violation
314 /// @pre <c>other(0, 0, 0...) == 0</c>, else @c ARENE_PRECONDITION violation
315 template <
316 class StridedLayoutMapping,
320 std::enable_if_t<StridedLayoutMapping::is_always_strided()>,
321 std::enable_if_t<StridedLayoutMapping::is_always_unique()>,
323 constexpr explicit mapping(StridedLayoutMapping const& other) noexcept
324 : base_type(
325 extents_type(other.extents()),
326 layout_detail::stride_cast<index_type>(
327 span<typename StridedLayoutMapping::index_type const, StridedLayoutMapping::extents_type::rank()>(
328 layout_detail::extract_strides(other)
329 )
330 )
331 ) {
332 // The second precondition is enforced by layout_detail::stride_cast
333 ARENE_PRECONDITION(arene::base::cmp_less_equal(other.required_span_size(), std::numeric_limits<index_type>::max()));
334 ARENE_PRECONDITION(layout_detail::get_offset_of_mapping(other) == typename StridedLayoutMapping::index_type{});
335 }
336
337 using base_type::extents;
338 using base_type::required_span_size;
339 using base_type::stride;
340 using base_type::strides;
341 using base_type::operator();
342
343 using base_type::is_always_strided;
344 using base_type::is_always_unique;
345 using base_type::is_strided;
346 using base_type::is_unique;
347
348 /// @brief Return whether or not this mapping is always exhaustive, i.e. every element is reachable using some indices
349 /// @return @c false because it's possible to construct non-exhaustive mappings using this class
350 /// @note In mathematical terms this asks if the mapping is always surjective/onto.
351 static constexpr auto is_always_exhaustive() noexcept -> bool { return false; }
352
353 /// @brief Return whether or not this instance is exhaustive, i.e. every element is reachable using some indices
354 /// @return @c true if every provided stride is the product of the extents corresponding to some subset of the other
355 /// strides, otherwise @c false
356 /// @note In mathematical terms this asks if the mapping is surjective/onto.
357 constexpr auto is_exhaustive() const noexcept -> bool {
358 return required_span_size() == layout_detail::extent_product(this->extents()).value;
359 }
360
361 // parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
362 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Hidden friends permitted by A11-3-1 Permit #2 v1.0.0"
363 // parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Mixed comparisons permitted by A13-5-5 Permit #1"
364 /// @brief Compare two strided mappings for equality, of which at least one must be a @c layout_stride::mapping
365 /// @tparam Right The type of the right side of the comparison; must be strided and satisfy @c is_layout_mapping_v
366 /// @param left An instance of @c layout_stride::mapping
367 /// @param right An instance of @c Right
368 /// @return @c true if @c left and @c right have the same extents and strides, and both map (0,0,...) to @c 0
369 template <
370 class Right,
373 std::enable_if_t<Right::extents_type::rank() == extents_type::rank()>,
374 std::enable_if_t<Right::is_always_strided()>> = nullptr>
375 friend constexpr auto operator==(mapping const& left, Right const& right) noexcept -> bool {
376 for (mapping::rank_type dim{}; dim < mapping::extents_type::rank(); ++dim) {
377 if (cmp_not_equal(left.extents().extent(dim), right.extents().extent(dim)) ||
378 cmp_not_equal(left.stride(dim), right.stride(dim))) {
379 return false;
380 }
381 }
382
383 return layout_detail::get_offset_of_mapping(right) == typename Right::index_type{};
384 }
385
386 /// @brief Compare two strided mappings for equality, of which at least one must be a @c layout_stride::mapping
387 /// @tparam Left The type of the left side of the comparison; must be strided and satisfy @c is_layout_mapping_v
388 /// @param left An instance of @c Left
389 /// @param right An instance of @c layout_stride::mapping
390 /// @return @c true if @c left and @c right have the same extents and strides, and both map (0,0,...) to @c 0
391 template <
392 class Left,
396 std::enable_if_t<Left::extents_type::rank() == extents_type::rank()>,
397 std::enable_if_t<Left::is_always_strided()>> = nullptr>
398 friend constexpr auto operator==(Left const& left, mapping const& right) noexcept -> bool {
399 return right == left;
400 }
401
402 /// @brief Compare two strided mappings for inequality, of which at least one must be a @c layout_stride::mapping
403 /// @tparam Right The type of the right side of the comparison; must be strided and satisfy @c is_layout_mapping_v
404 /// @param left An instance of @c layout_stride::mapping
405 /// @param right An instance of @c Right
406 /// @return @c true if @c left and @c right have different extents or strides, or one doesn't map (0,0,...) to @c 0
407 template <
408 class Right,
411 std::enable_if_t<Right::extents_type::rank() == extents_type::rank()>,
412 std::enable_if_t<Right::is_always_strided()>> = nullptr>
413 friend constexpr auto operator!=(mapping const& left, Right const& right) noexcept -> bool {
414 return !(left == right);
415 }
416
417 /// @brief Compare two strided mappings for inequality, of which at least one must be a @c layout_stride::mapping
418 /// @tparam Left The type of the left side of the comparison; must be strided and satisfy @c is_layout_mapping_v
419 /// @param left An instance of @c Left
420 /// @param right An instance of @c layout_stride::mapping
421 /// @return @c true if @c left and @c right have different extents or strides, or one doesn't map (0,0,...) to @c 0
422 template <
423 class Left,
427 std::enable_if_t<Left::extents_type::rank() == extents_type::rank()>,
428 std::enable_if_t<Left::is_always_strided()>> = nullptr>
429 friend constexpr auto operator!=(Left const& left, mapping const& right) noexcept -> bool {
430 return !(right == left);
431 }
432 // parasoft-end-suppress AUTOSAR-M3_3_2-a-2
433 // parasoft-end-suppress AUTOSAR-A11_3_1-a
434 // parasoft-end-suppress AUTOSAR-A13_5_5-b-2
435
436 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Hidden friends permitted by A11-3-1 Permit #2"
437 /// @brief compute submdspan mapping and offset for a @c layout_stride mapping
438 /// @tparam CanonicalSliceSpecifiers submdspan slice specifier types
439 /// @param src source @c layout_stride::mapping to slice
440 /// @param slices submdspan slice specifiers
441 ///
442 /// Uses @c slices to compute the sub-extents, sub-strides, and offset of the submdspan. The @c slices must be in
443 /// canonical form.
444 ///
445 /// @return A @c submdspan_mapping_result containing the sub-mapping and offset such that indexing the sub-mapping and
446 /// adding the offset recovers the corresponding index in the original mapping.
447 ///
448 /// @note Constraints <br>
449 /// * <c> sizeof...(CanonicalSliceSpecifiers) == extents_type::rank() </c>
450 /// * for each rank index @c k of @c src.extents(), @c CanonicalSliceSpecifiers...[k] is a valid submdspan slice
451 /// type for the @c k-th extent of @c extents_type
452 ///
453 /// @note Preconditions <br>
454 /// * for each rank index @c k of @c src.extents(), @c slices...[k] denotes a valid submdspan slice for the @c k-th
455 /// extent of @c src.extents()
456 ///
457 /// @note Remarks <br>
458 /// * this function is found via argument-dependent lookup as a @c friend of @c layout_stride::mapping
459 /// * the @c layout_stride specialization of @c submdspan_mapping always produces a @c layout_stride mapping for the
460 /// submdspan.
461 template <
462 class SrcMapping,
463 class... CanonicalSliceSpecifiers,
465 std::enable_if_t<sizeof...(CanonicalSliceSpecifiers) == extents_type::rank()>,
467 mdspan_detail::all_valid_submdspan_slice_types_for_v<extents_type, CanonicalSliceSpecifiers...>>> =
468 nullptr>
469 friend constexpr auto submdspan_mapping(SrcMapping const& src, CanonicalSliceSpecifiers... slices) noexcept
471 layout_stride::mapping<submdspan_subextents_type_t<extents_type, CanonicalSliceSpecifiers...>>> {
472 // precondition is transitively checked by submdspan_extents -> submdspan_canonicalize_slices
473 auto sub_strides = mdspan_detail::submdspan_sub_strides<index_type>(src, slices...);
474 auto offset = mdspan_detail::submdspan_offset(src, slices...);
475 auto sub_ext = submdspan_extents(src.extents(), std::move(slices)...);
476
477 using submapping = layout_stride::mapping<submdspan_subextents_type_t<extents_type, CanonicalSliceSpecifiers...>>;
478 return {submapping{std::move(sub_ext), std::move(sub_strides), mapping::passkey()}, offset};
479 }
480 // parasoft-end-suppress AUTOSAR-A11_3_1-a
481};
482// parasoft-end-suppress AUTOSAR-A14_5_1-a
483// parasoft-end-suppress AUTOSAR-A12_1_5-a
484
485/// @brief Specialization of @c is_layout_mapping_v to break a recursive cycle in the @c layout_stride equality operator
486/// @tparam Extents Any specialization of @c arene::base::extents
487template <typename Extents>
488extern constexpr bool is_layout_mapping_v<layout_stride::mapping<Extents>> = true;
489
490} // namespace base
491} // namespace arene
492
493// parasoft-end-suppress AUTOSAR-M2_10_1-a "Similar names permitted by M2-10-1 Permit #1"
494// parasoft-end-suppress AUTOSAR-A7_1_5-a-2
495
496#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_LAYOUT_STRIDE_HPP_
A fixed-size array of T objects.
Definition array.hpp:77
represents a multidimensional index space
Definition extents.hpp:72
A mapping from a logical pack of indices into a single flat physical output index,...
Definition layout_stride.hpp:192
friend constexpr auto operator!=(Left const &left, mapping const &right) noexcept -> bool
Compare two strided mappings for inequality, of which at least one must be a layout_stride::mapping.
Definition layout_stride.hpp:429
friend constexpr auto operator!=(mapping const &left, Right const &right) noexcept -> bool
Compare two strided mappings for inequality, of which at least one must be a layout_stride::mapping.
Definition layout_stride.hpp:413
constexpr mapping(StridedLayoutMapping const &other) noexcept
Construct a mapping from another strided mapping; implicit for certain known-safe mapping types.
Definition layout_stride.hpp:295
friend constexpr auto operator==(Left const &left, mapping const &right) noexcept -> bool
Compare two strided mappings for equality, of which at least one must be a layout_stride::mapping.
Definition layout_stride.hpp:398
constexpr mapping(extents_type const &exts, array< OtherIndexType, extents_type::rank()> const &strds) noexcept
Construct a mapping with the given strides; they must be valid for a default-constructed extents_type...
Definition layout_stride.hpp:276
friend constexpr auto operator==(mapping const &left, Right const &right) noexcept -> bool
Compare two strided mappings for equality, of which at least one must be a layout_stride::mapping.
Definition layout_stride.hpp:375
static constexpr auto is_always_exhaustive() noexcept -> bool
Return whether or not this mapping is always exhaustive, i.e. every element is reachable using some i...
Definition layout_stride.hpp:351
constexpr auto is_exhaustive() const noexcept -> bool
Return whether or not this instance is exhaustive, i.e. every element is reachable using some indices...
Definition layout_stride.hpp:357
constexpr mapping(extents_type const &exts, array< index_type, extents_type::rank()> const &strds, layout_detail::check_bypasser) noexcept
Construct a mapping with the given strides, bypassing precondition checks.
Definition layout_stride.hpp:226
constexpr mapping() noexcept
Construct a default strided mapping for the given extents, which has the same layout as layout_right.
Definition layout_stride.hpp:235
layout_stride layout_type
The tag type of the layout used by this mapping.
Definition layout_stride.hpp:203
friend constexpr auto submdspan_mapping(SrcMapping const &src, CanonicalSliceSpecifiers... slices) noexcept -> submdspan_mapping_result< layout_stride::mapping< submdspan_subextents_type_t< extents_type, CanonicalSliceSpecifiers... > > >
compute submdspan mapping and offset for a layout_stride mapping
Definition layout_stride.hpp:469
constexpr mapping(extents_type const &exts, span< OtherIndexType, extents_type::rank()> strds) noexcept
Construct a mapping with the given strides; they must be valid for a default-constructed extents_type...
Definition layout_stride.hpp:252
A backport of std::span for C++14. Provides a view over a contiguous range of elements of type T.
Definition span.hpp:315
static constexpr auto max() noexcept -> T
The maximum finite value.
Definition numeric_limits.hpp:230
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Definition accumulate.hpp:37
constexpr bool is_layout_mapping_v
Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
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
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
bool_constant< false > false_type
An alias for bool_constant<false>
Definition integral_constant.hpp:79
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
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
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
Provides backports of the safe integer comparison functions from C++20.
Specializations of submdspan_mapping_result are returned by overloads of submdspan_mapping.
Definition submdspan_mapping_result.hpp:18