8#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_MDSPAN_HPP_
9#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_MDSPAN_HPP_
15#include "arene/base/detail/dynamic_extent.hpp"
18#include "arene/base/mdspan/detail/representable_cast.hpp"
19#include "arene/base/mdspan/detail/tuple_span.hpp"
25#include "arene/base/stdlib_choice/cstddef.hpp"
26#include "arene/base/stdlib_choice/declval.hpp"
27#include "arene/base/stdlib_choice/enable_if.hpp"
28#include "arene/base/stdlib_choice/integral_constant.hpp"
29#include "arene/base/stdlib_choice/is_abstract.hpp"
30#include "arene/base/stdlib_choice/is_array.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_default_constructible.hpp"
34#include "arene/base/stdlib_choice/is_object.hpp"
35#include "arene/base/stdlib_choice/is_same.hpp"
36#include "arene/base/stdlib_choice/move.hpp"
37#include "arene/base/stdlib_choice/remove_cv.hpp"
50namespace mdspan_detail {
54template <
typename Extents>
55extern constexpr bool all_extents_are_dynamic_v = Extents::rank() == Extents::rank_dynamic();
59template <
typename Extents>
60extern constexpr bool all_extents_are_static_v = Extents::rank_dynamic() == 0;
77 TargetExtents::rank() == 0 || all_extents_are_dynamic_v<TargetExtents> ||
78 all_extents_are_static_v<SourceExtents>>> =
nullptr>
79constexpr auto validate_extents_compatibility(SourceExtents
const&) ->
void {}
99constexpr auto validate_extents_compatibility(SourceExtents
const& source) ->
void {
123constexpr auto validate_extents_compatibility(SourceExtents
const& source) ->
void {
129 (TargetExtents::static_extent(dim) == arene::base::dynamic_extent) ||
130 cmp_equal(TargetExtents::static_extent(dim), source.extent(dim))
151 typename ElementType,
153 typename LayoutPolicy = layout_right,
157 :
private AccessorPolicy
158 ,
private LayoutPolicy::template
mapping<Extents> {
162 static_assert(
is_extents_v<Extents>,
"Extents type parameter must be a specialization of arene::base::extents");
166 "ElementType must match AccessorPolicy::element_type"
170 "LayoutPolicy must meet the layout mapping policy requirements for the given Extents"
219 return extents_type::static_extent(dimension);
238 typename Ext = Extents,
240 typename Acc = AccessorPolicy,
267 class... OtherIndexTypes,
268 typename Ext = Extents,
270 typename Acc = AccessorPolicy,
272 std::enable_if_t<all_of_v<std::is_convertible<OtherIndexTypes, index_type>::value...>>,
273 std::enable_if_t<all_of_v<std::is_nothrow_constructible<index_type, OtherIndexTypes>::value...>>,
275 std::enable_if_t<std::is_constructible<Map, Ext>::value>,
276 std::enable_if_t<std::is_default_constructible<Acc>::value>> =
nullptr>
297 class OtherIndexType,
299 typename Ext = Extents,
301 typename Acc = AccessorPolicy,
327 class OtherIndexType,
328 typename Ext = Extents,
330 typename Acc = AccessorPolicy,
354 class OtherIndexType,
356 typename Ext = Extents,
358 typename Acc = AccessorPolicy,
384 class OtherIndexType,
385 typename Ext = Extents,
387 typename Acc = AccessorPolicy,
409 typename Ext = Extents,
411 typename Acc = AccessorPolicy,
433 typename Acc = AccessorPolicy,
434 constraints<std::enable_if_t<std::is_default_constructible<Acc>::value>> =
nullptr>
460 template <
class OtherExtents,
class OtherLayoutPolicy,
class OtherAccessor>
461 static constexpr bool converting_constructor_is_explicit_v{
462 !std::is_convertible<typename OtherLayoutPolicy::template mapping<OtherExtents>
const&,
mapping_type>::value ||
484 class OtherElementType,
486 class OtherLayoutPolicy,
493 std::enable_if_t<std::is_constructible<accessor_type, OtherAccessor const&>::value>,
496 std::enable_if_t<std::is_constructible<extents_type, OtherExtents const&>::value>> =
nullptr>
501 mdspan_detail::validate_extents_compatibility<extents_type>(other.extents());
523 class OtherElementType,
525 class OtherLayoutPolicy,
541 mdspan_detail::validate_extents_compatibility<extents_type>(other.extents());
562 using mapping_type::extents;
587 class... OtherIndexTypes,
591 std::enable_if_t<
sizeof...(OtherIndexTypes) == extents_type::rank>> =
nullptr>
592 constexpr auto operator()(OtherIndexTypes... indices)
const
603 mdspan_detail::representable_cast<std::size_t>(this->
mapping()(
std::move(indices)...))
612 class OtherIndexType,
620 array<OtherIndexType, extents_type::rank()>
const&>)
622 return apply(*
this, indices);
630 class OtherIndexType,
638 mdspan_detail::tuple_span<OtherIndexType, extents_type::rank>
const&>)
640 return apply(*
this, mdspan_detail::tuple_span<OtherIndexType, extents_type::rank>(indices));
647 using mapping_type::is_always_unique;
653 using mapping_type::is_always_exhaustive;
658 using mapping_type::is_always_strided;
663 using mapping_type::is_unique;
669 using mapping_type::is_exhaustive;
674 using mapping_type::is_strided;
680 using mapping_type::stride;
721template <
typename ElementType,
typename Extents,
typename LayoutPolicy,
typename AccessorPolicy>
723 integral_constant<typename mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::rank_type, Extents::rank()>
731template <
typename ElementType,
typename Extents,
typename LayoutPolicy,
typename AccessorPolicy>
734 Extents::rank_dynamic()>
737namespace is_mdspan_detail {
748template <
typename ElementType,
typename Extents,
typename LayoutPolicy,
typename AccessorPolicy>
755extern constexpr bool is_mdspan_v{is_mdspan_detail::is_mdspan_v<std::remove_cv_t<T>>};
A fixed-size array of T objects.
Definition array.hpp:77
accesses a single element from a pointer and an index
Definition default_accessor.hpp:32
ElementType * data_handle_type
data handle type Refers to a group of elements. In this case, a pointer.
Definition default_accessor.hpp:48
constexpr auto access(data_handle_type ptr, std::size_t index) const noexcept -> reference
obtain the element at the specified index
Definition default_accessor.hpp:73
ElementType & reference
reference type Returned on element to access. In this case, an lvalue reference.
Definition default_accessor.hpp:45
represents a multidimensional index space
Definition extents.hpp:72
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 extents.hpp:294
constexpr mdspan(data_handle_type handle, array< OtherIndexType, rank_dynamic()> const &extents_in) noexcept
Construct mdspan with a data handle and extents.
Definition mdspan.hpp:393
friend constexpr auto swap(mdspan &lhs, mdspan &rhs) noexcept -> void
swaps the contents
Definition mdspan.hpp:692
constexpr mdspan(data_handle_type handle, mapping_type const &mapping_in, accessor_type const &accessor_in) noexcept
Construct mdspan with a data handle, mapping, and accessor.
Definition mdspan.hpp:450
constexpr auto operator()(array< OtherIndexType, extents_type::rank > const &indices) const noexcept(arene::base::is_nothrow_invocable_v<, mdspan const &, array< OtherIndexType, extents_type::rank()> const & >) -> reference
Access an element with an array of indices.
Definition mdspan.hpp:616
static constexpr std::integral_constant< rank_type, Extents::rank_dynamic()> rank_dynamic
Definition mdspan.hpp:210
ElementType element_type
Definition mdspan.hpp:183
typename extents_type::index_type index_type
Definition mdspan.hpp:192
constexpr auto empty() const noexcept -> bool
Check if the size is zero.
Definition mdspan.hpp:558
constexpr auto accessor() const noexcept -> accessor_type const &
Definition mdspan.hpp:580
constexpr mdspan(data_handle_type handle, extents_type const &extents_in) noexcept
Construct mdspan with a data handle and extents.
Definition mdspan.hpp:416
Extents extents_type
Definition mdspan.hpp:175
constexpr mdspan(data_handle_type handle, span< OtherIndexType, Size > extents_in) noexcept
Construct mdspan with a data handle and extents.
Definition mdspan.hpp:309
constexpr auto size() const noexcept -> size_type
Get the size of the multidimensional index space.
Definition mdspan.hpp:549
constexpr mdspan(data_handle_type handle, span< OtherIndexType, rank_dynamic()> extents_in) noexcept
Construct mdspan with a data handle and extents.
Definition mdspan.hpp:336
constexpr auto data_handle() const noexcept -> data_handle_type const &
Definition mdspan.hpp:568
typename extents_type::size_type size_type
Definition mdspan.hpp:194
default_accessor< ElementType > accessor_type
Definition mdspan.hpp:179
constexpr auto operator()(span< OtherIndexType, extents_type::rank > const indices) const noexcept(arene::base::is_nothrow_invocable_v<, mdspan const &, mdspan_detail::tuple_span< OtherIndexType, extents_type::rank > const & >) -> reference
Access an mdspan element with a span of indices.
Definition mdspan.hpp:634
static constexpr std::integral_constant< rank_type, Extents::rank()> rank
Definition mdspan.hpp:206
constexpr mdspan() noexcept
Default constructor.
Definition mdspan.hpp:246
static constexpr auto static_extent(rank_type dimension) noexcept -> std::size_t
Get the static extent for the given dimension.
Definition mdspan.hpp:218
constexpr mdspan(data_handle_type handle, mapping_type const &mapping_in) noexcept
Construct mdspan with a data handle and mapping.
Definition mdspan.hpp:435
constexpr mdspan(data_handle_type handle, array< OtherIndexType, Size > const &extents_in) noexcept
Construct mdspan with a data handle and extents.
Definition mdspan.hpp:366
typename layout_type::template mapping< extents_type > mapping_type
Definition mdspan.hpp:181
constexpr mdspan(data_handle_type handle, OtherIndexTypes... extents_in) noexcept
Construct mdspan with a data handle and extents.
Definition mdspan.hpp:277
constexpr auto mapping() const noexcept -> mapping_type const &
Get the mapping.
Definition mdspan.hpp:575
layout_constant_diagonal< extents< std::size_t, 0U, 0U > > layout_type
Definition mdspan.hpp:177
std::remove_cv_t< element_type > value_type
Definition mdspan.hpp:188
typename accessor_type::data_handle_type data_handle_type
Definition mdspan.hpp:198
typename accessor_type::reference reference
Definition mdspan.hpp:200
constexpr mdspan(mdspan< OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor > const &other)
Converting constructor from another mdspan.
Definition mdspan.hpp:497
typename extents_type::rank_type rank_type
Definition mdspan.hpp:196
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:226
A backport of std::span for C++14. Provides a view over a contiguous range of elements of type T.
Definition span.hpp:315
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
static constexpr value_type value
Definition integral_constant.hpp:34
Type trait to detect if a type is constructible from arguments of the specified types.
Definition is_constructible.hpp:29
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
static ARENE_MAYBE_UNUSED constexpr auto const & swap
A Customization Point Object implementation of the constexpr compatible std::swap from C++17.
Definition swap.hpp:130
Definition accumulate.hpp:37
constexpr bool is_mdspan_v
Type trait to determine if the given type is an mdspan of some kind.
constexpr bool is_accessor_policy_v
Check if a type is a valid accessor policy.
constexpr auto sequential_values
An array holding a sequence of integer values starting at 0, incrementing by 1 each time.
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.
constexpr bool is_nothrow_invocable_v
Determine if a functor type is no-throw invocable with the specified argument types.
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 remove_cv< T >::type remove_cv_t
An alias for T, but with top-level const and/or volatile qualifiers removed.
Definition remove_cv.hpp:64
::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
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
Provides backports of the safe integer comparison functions from C++20.
Provides the all_of_v<bool...> trait.