8#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_LAYOUT_LEFT_HPP_
9#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_LAYOUT_LEFT_HPP_
17#include "arene/base/mdspan/detail/all_valid_submdspan_slice_types_for.hpp"
18#include "arene/base/mdspan/detail/checked_math.hpp"
19#include "arene/base/mdspan/detail/is_submdspan_layout_preserving.hpp"
20#include "arene/base/mdspan/detail/layout_common.hpp"
21#include "arene/base/mdspan/detail/strided_mapping_base.hpp"
22#include "arene/base/mdspan/detail/submdspan_mapping_impl.hpp"
24#include "arene/base/stdlib_choice/enable_if.hpp"
25#include "arene/base/stdlib_choice/is_constructible.hpp"
26#include "arene/base/stdlib_choice/is_convertible.hpp"
27#include "arene/base/stdlib_choice/move.hpp"
35namespace layout_detail {
43template <
typename Extents, constra
ints<std::enable_if_t<Extents::rank() != 0U>> =
nullptr>
44constexpr auto left_strides(Extents
const& extents)
noexcept
45 -> ::arene::base::array<
typename Extents::index_type, Extents::rank()> {
46 using index_type =
typename Extents::index_type;
47 using rank_type =
typename Extents::rank_type;
49 ::arene::base::array<index_type, Extents::rank()> strides{};
50 mdspan_detail::checked_math_result<index_type> current_stride{index_type{1}};
51 strides[0U] = current_stride.value;
52 for (rank_type dim{}; dim + rank_type{1} < Extents::rank(); ++dim) {
53 current_stride = mdspan_detail::checked_multiplies<index_type>(current_stride, extents.extent(dim));
54 if (current_stride.value == index_type{}) {
57 current_stride.value = index_type{1};
59 strides[dim + rank_type{1}] = current_stride.value;
71template <
typename Extents, constra
ints<std::enable_if_t<Extents::rank() == 0U>> =
nullptr>
72constexpr auto left_strides(Extents
const&)
noexcept
73 -> ::arene::base::array<
typename Extents::index_type, Extents::rank()> {
85template <
class Extents>
89 using base_type = layout_detail::strided_mapping_base<Extents>;
92 using typename base_type::extents_type;
93 using typename base_type::index_type;
94 using typename base_type::rank_type;
95 using typename base_type::size_type;
110 constexpr mapping(extents_type
const& exts) noexcept
111 : base_type(exts, layout_detail::left_strides(exts)) {}
121 typename OtherExtents,
125 :
mapping(layout_detail::extents_cast<extents_type>(other.extents())) {}
136 typename OtherExtents,
141 :
mapping(layout_detail::extents_cast<extents_type>(other.extents())) {}
152 typename OtherExtents,
158 :
mapping(layout_detail::extents_cast<extents_type>(other.extents())) {}
169 typename OtherExtents,
175 :
mapping(layout_detail::extents_cast<extents_type>(other.extents())) {}
188 typename OtherExtents,
194 :
mapping(layout_detail::extents_cast<extents_type>(other.extents())) {
209 typename OtherExtents,
214 :
mapping(layout_detail::extents_cast<extents_type>(other.extents())) {
216 layout_detail::precondition_strides_equal<index_type, typename OtherExtents::index_type>(
223 using base_type::extents;
224 using base_type::required_span_size;
225 using base_type::stride;
226 using base_type::operator();
228 using base_type::is_always_strided;
229 using base_type::is_always_unique;
230 using base_type::is_strided;
231 using base_type::is_unique;
252 typename OtherExtents,
255 return left.extents() == right.extents();
264 typename OtherExtents,
267 return !(left == right);
280 static constexpr auto passkey() noexcept -> layout_detail::check_bypasser {
return layout_detail::check_bypasser{}; }
292 static constexpr auto strides_of(
mapping const& src)
noexcept
294 return src.strides();
333 class... CanonicalSliceSpecifiers,
335 std::enable_if_t<
sizeof...(CanonicalSliceSpecifiers) == extents_type::rank()>,
337 mdspan_detail::all_valid_submdspan_slice_types_for_v<extents_type, CanonicalSliceSpecifiers...>>> =
341#ifdef ARENE_DOC_GENERATION_RUNNING
344 ->
decltype(mdspan_detail::submdspan_mapping_impl<
346 mdspan_detail::is_submdspan_layout_preserving<
349 CanonicalSliceSpecifiers...>{},
352 mapping::strides_of(src),
355 return mdspan_detail::submdspan_mapping_impl<
357 mdspan_detail::is_submdspan_layout_preserving<
360 CanonicalSliceSpecifiers...>{},
A fixed-size array of T objects.
Definition array.hpp:77
A mapping from a logical pack of indices into a single flat physical output index.
Definition layout_left.hpp:86
friend constexpr auto operator!=(mapping const &left, mapping< OtherExtents > const &right) noexcept -> bool
Compare two left-strided mappings for inequality.
Definition layout_left.hpp:266
constexpr mapping(layout_stride::mapping< OtherExtents > const &other) noexcept
Converting constructor from a layout_stride::mapping with a compatible extents_type.
Definition layout_left.hpp:193
friend constexpr auto operator==(mapping const &left, mapping< OtherExtents > const &right) noexcept -> bool
Compare two left-strided mappings for equality.
Definition layout_left.hpp:254
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_left.hpp:236
layout_left layout_type
The tag type of the layout used by this mapping.
Definition layout_left.hpp:97
constexpr mapping(layout_right::mapping< OtherExtents > const &other) noexcept
Converting constructor from a layout_right::mapping when both have 0- or 1-dimensional extents.
Definition layout_left.hpp:157
constexpr mapping(mapping< OtherExtents > const &other) noexcept
Converting constructor from a mapping with a different (but compatible) extents_type.
Definition layout_left.hpp:124
constexpr mapping(extents_type const &exts) noexcept
Construct a left-strided mapping for the given extents.
Definition layout_left.hpp:110
constexpr mapping() noexcept
Construct a default left-strided mapping for the given extents.
Definition layout_left.hpp:101
friend constexpr auto submdspan_mapping(mapping const &src, CanonicalSliceSpecifiers... slices) noexcept
Compute the sub-mapping for a layout_left::mapping.
static constexpr auto is_exhaustive() noexcept -> bool
Return whether or not this instance is exhaustive, i.e. every element is reachable using some indices...
Definition layout_left.hpp:242
A mapping from a logical pack of indices into a single flat physical output index.
Definition layout_right.hpp:41
A mapping from a logical pack of indices into a single flat physical output index,...
Definition layout_stride.hpp:192
#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
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
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
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