5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_MDSPAN_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_MDSPAN_HPP_
9#include "arene/base/array/array.hpp"
10#include "arene/base/constraints/constraints.hpp"
11#include "arene/base/contracts/contract.hpp"
12#include "arene/base/detail/dynamic_extent.hpp"
13#include "arene/base/integer_sequences/sequential_values.hpp"
14#include "arene/base/mdspan/default_accessor.hpp"
15#include "arene/base/mdspan/detail/representable_cast.hpp"
16#include "arene/base/mdspan/detail/tuple_span.hpp"
17#include "arene/base/mdspan/extents.hpp"
18#include "arene/base/mdspan/is_accessor_policy.hpp"
19#include "arene/base/mdspan/is_layout_mapping.hpp"
20#include "arene/base/mdspan/layout.hpp"
21#include "arene/base/span/span.hpp"
22#include "arene/base/stdlib_choice/cstddef.hpp"
23#include "arene/base/stdlib_choice/declval.hpp"
24#include "arene/base/stdlib_choice/enable_if.hpp"
25#include "arene/base/stdlib_choice/integral_constant.hpp"
26#include "arene/base/stdlib_choice/is_abstract.hpp"
27#include "arene/base/stdlib_choice/is_array.hpp"
28#include "arene/base/stdlib_choice/is_constructible.hpp"
29#include "arene/base/stdlib_choice/is_convertible.hpp"
30#include "arene/base/stdlib_choice/is_default_constructible.hpp"
31#include "arene/base/stdlib_choice/is_object.hpp"
32#include "arene/base/stdlib_choice/is_same.hpp"
33#include "arene/base/stdlib_choice/move.hpp"
34#include "arene/base/stdlib_choice/remove_cv.hpp"
35#include "arene/base/tuple/apply.hpp"
36#include "arene/base/type_traits/all_of.hpp"
37#include "arene/base/type_traits/is_invocable.hpp"
38#include "arene/base/utility/safe_comparisons.hpp"
39#include "arene/base/utility/swap.hpp"
47namespace mdspan_detail {
51template <
typename Extents>
52extern constexpr bool all_extents_are_dynamic_v = Extents::rank() == Extents::rank_dynamic();
56template <
typename Extents>
57extern constexpr bool all_extents_are_static_v = Extents::rank_dynamic() == 0;
73 arene::base::constraints<std::enable_if_t<
74 TargetExtents::rank() == 0 || all_extents_are_dynamic_v<TargetExtents> ||
75 all_extents_are_static_v<SourceExtents>>> =
nullptr>
76constexpr auto validate_extents_compatibility(SourceExtents
const&) ->
void {}
92 arene::base::constraints<
93 std::enable_if_t<TargetExtents::rank() != 0>,
94 std::enable_if_t<!all_extents_are_static_v<SourceExtents>>,
95 std::enable_if_t<all_extents_are_static_v<TargetExtents>>> =
nullptr>
96constexpr auto validate_extents_compatibility(SourceExtents
const& source) ->
void {
98 for (
auto dim : arene::base::sequential_values<
typename TargetExtents::rank_type, TargetExtents::rank()>) {
101 ARENE_PRECONDITION(cmp_equal(TargetExtents::static_extent(dim), source.extent(dim)));
115 arene::base::constraints<
116 std::enable_if_t<TargetExtents::rank() != 0>,
117 std::enable_if_t<!all_extents_are_static_v<SourceExtents>>,
118 std::enable_if_t<!all_extents_are_static_v<TargetExtents>>,
119 std::enable_if_t<!all_extents_are_dynamic_v<TargetExtents>>> =
nullptr>
120constexpr auto validate_extents_compatibility(SourceExtents
const& source) ->
void {
122 for (
auto dim : arene::base::sequential_values<
typename TargetExtents::rank_type, TargetExtents::rank()>) {
126 (TargetExtents::static_extent(dim) == arene::base::dynamic_extent) ||
127 cmp_equal(TargetExtents::static_extent(dim), source.extent(dim))
148 typename ElementType,
154 :
private AccessorPolicy
155 ,
private LayoutPolicy::
template mapping<Extents> {
159 static_assert(
is_extents_v<
Extents>,
"Extents type parameter must be a specialization of arene::base::extents");
163 "ElementType must match AccessorPolicy::element_type"
167 "LayoutPolicy must meet the layout mapping policy requirements"
172 using extents_type = Extents;
174 using layout_type = LayoutPolicy;
176 using accessor_type = AccessorPolicy;
178 using mapping_type =
typename layout_type::
template mapping<extents_type>;
180 using element_type = ElementType;
185 using index_type =
typename extents_type::index_type;
187 using size_type =
typename extents_type::size_type;
189 using rank_type =
typename extents_type::rank_type;
191 using data_handle_type =
typename accessor_type::data_handle_type;
193 using reference =
typename accessor_type::reference;
212 return extents_type::static_extent(dimension);
219 constexpr auto extent(rank_type dimension)
const noexcept -> index_type {
return this->extents().extent(dimension); }
559 constexpr auto data_handle()
const noexcept -> data_handle_type
const& {
return ptr_; }
566 constexpr auto mapping()
const noexcept -> mapping_type
const& {
return *
this; }
571 constexpr auto accessor()
const noexcept -> accessor_type
const& {
return *
this; }
644 using mapping_type::is_always_exhaustive;
649 using mapping_type::is_always_strided;
654 using mapping_type::is_unique;
660 using mapping_type::is_exhaustive;
665 using mapping_type::is_strided;
671 using mapping_type::stride;
684 arene::base::swap(lhs.ptr_, rhs.ptr_);
685 arene::base::swap(
static_cast<mapping_type&>(lhs),
static_cast<mapping_type&>(rhs));
686 arene::base::swap(
static_cast<accessor_type&>(lhs),
static_cast<accessor_type&>(rhs));
699 data_handle_type ptr_;
712template <
typename ElementType,
typename Extents,
typename LayoutPolicy,
typename AccessorPolicy>
715 mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::
rank;
722template <
typename ElementType,
typename Extents,
typename LayoutPolicy,
typename AccessorPolicy>
728namespace is_mdspan_detail {
732extern constexpr bool is_mdspan_v{
false};
739template <
typename ElementType,
typename Extents,
typename LayoutPolicy,
typename AccessorPolicy>
740extern constexpr bool is_mdspan_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
true};
A multidimensional view of elements over a contiguous sequence of elements.
Definition mdspan.hpp:155
friend constexpr auto swap(mdspan &lhs, mdspan &rhs) noexcept -> void
swaps the contents
Definition mdspan.hpp:683
static constexpr std::integral_constant< rank_type, Extents::rank_dynamic()> rank_dynamic
Get the number of dimensions with dynamic extent.
Definition mdspan.hpp:203
constexpr auto accessor() const noexcept -> accessor_type const &
Get the accessor.
Definition mdspan.hpp:571
constexpr auto data_handle() const noexcept -> data_handle_type const &
Get the data handle.
Definition mdspan.hpp:559
static constexpr std::integral_constant< rank_type, Extents::rank()> rank
Get the number of dimensions.
Definition mdspan.hpp:199
static constexpr auto static_extent(rank_type dimension) noexcept -> std::size_t
Get the static extent for the given dimension.
Definition mdspan.hpp:211
constexpr auto mapping() const noexcept -> mapping_type const &
Get the mapping.
Definition mdspan.hpp:566
constexpr auto extent(rank_type dimension) const noexcept -> index_type
Get the actual extent for the given dimension, returning the extent supplied to the constructor for d...
Definition mdspan.hpp:219
Definition array_exceptions_disabled.cpp:11
constexpr bool is_mdspan_v
Type trait to determine if the given type is an mdspan of some kind.
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10