5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_EXTENTS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_EXTENTS_HPP_
12#include "arene/base/detail/dynamic_extent.hpp"
14#include "arene/base/mdspan/detail/deduced_static_extent.hpp"
15#include "arene/base/mdspan/detail/extent_sequence.hpp"
16#include "arene/base/mdspan/detail/extract_dynamic_extents_for.hpp"
17#include "arene/base/mdspan/detail/to_array.hpp"
19#include "arene/base/stdlib_choice/cstddef.hpp"
20#include "arene/base/stdlib_choice/enable_if.hpp"
21#include "arene/base/stdlib_choice/forward.hpp"
22#include "arene/base/stdlib_choice/integer_sequence.hpp"
23#include "arene/base/stdlib_choice/integral_constant.hpp"
24#include "arene/base/stdlib_choice/is_constructible.hpp"
25#include "arene/base/stdlib_choice/is_convertible.hpp"
26#include "arene/base/stdlib_choice/is_integral.hpp"
27#include "arene/base/stdlib_choice/is_same.hpp"
28#include "arene/base/stdlib_choice/make_unsigned.hpp"
29#include "arene/base/stdlib_choice/move.hpp"
30#include "arene/base/stdlib_choice/numeric_limits.hpp"
39namespace extents_detail {
52static constexpr bool valid_extents_template_parameters_v{
68template <
typename IndexType,
std::size_t... Extents>
70 : mdspan_detail::extent_sequence<Extents...>
71 ,
array<IndexType, mdspan_detail::extent_sequence<Extents...>::rank_dynamic>
74 using extent_sequence_type = mdspan_detail::extent_sequence<Extents...>;
81 constexpr auto dynamic_extents()
const noexcept -> dynamic_extents_storage_type
const&
83 return static_cast<dynamic_extents_storage_type const&
>(*this);
90 template <
class OtherIndexType,
class OtherExtentSequence>
91 static constexpr bool copy_from_other_extents_is_explicit_v{
93 !mdspan_detail::extent_sequence_equal(
94 extent_sequence_type{},
95 OtherExtentSequence{},
96 not_fn(mdspan_detail::left_static_extent_and_right_dynamic_extent{})
102 extents_detail::valid_extents_template_parameters_v<IndexType, Extents...>,
103 "invalid template parameters for 'extents'"
112 using rank_type =
typename extent_sequence_type::rank_type;
115 using extent_sequence_type::rank;
116 using extent_sequence_type::rank_dynamic;
117 using extent_sequence_type::static_extent;
129 typename OtherIndexType,
138 : extent_sequence_type{},
139 dynamic_extents_storage_type{mdspan_detail::extract_dynamic_extents_for<extents>(exts)}
149 typename OtherIndexType,
155 : extent_sequence_type{},
156 dynamic_extents_storage_type{mdspan_detail::extract_dynamic_extents_for<extents>(exts)}
168 typename OtherIndexType,
174 : extent_sequence_type{},
175 dynamic_extents_storage_type{mdspan_detail::extract_dynamic_extents_for<extents>(exts)}
188 typename OtherIndexType,
197 : extent_sequence_type{},
198 dynamic_extents_storage_type{mdspan_detail::extract_dynamic_extents_for<extents>(exts)}
208 typename... OtherIndexTypes,
214 explicit constexpr extents(OtherIndexTypes... exts) noexcept
228 typename... OtherIndexTypes,
235 explicit constexpr extents(OtherIndexTypes... exts) noexcept
246 typename OtherIndexType,
250 !copy_from_other_extents_is_explicit_v<OtherIndexType, mdspan_detail::extent_sequence<OtherExtents...>>>,
253 (Extents == OtherExtents) || (Extents == dynamic_extent) || (OtherExtents == dynamic_extent)>...> =
257 :
extents{mdspan_detail::extract_dynamic_extents_for<extents>(mdspan_detail::to_array(source_extents))}
267 typename OtherIndexType,
271 copy_from_other_extents_is_explicit_v<OtherIndexType, mdspan_detail::extent_sequence<OtherExtents...>>>,
274 (Extents == OtherExtents) || (Extents == dynamic_extent) || (OtherExtents == dynamic_extent)>...> =
277 :
extents{mdspan_detail::extract_dynamic_extents_for<extents>(mdspan_detail::to_array(source_extents))}
295 auto const default_extent = extents::static_extent(dimension);
296 if (default_extent == dynamic_extent) {
298 return dynamic_extents()[extent_sequence_type::dynamic_index_map[dimension]];
301 return static_cast<index_type>(default_extent);
316 typename OtherIndexType,
338 typename OtherIndexType,
355 template <
typename OtherIndexType,
std::size_t... OtherExtents>
358 return !(lhs == rhs);
368namespace extents_detail {
374template <
class IndexType,
class IndexSequence>
375class dextents_helper {};
382class dextents_helper<IndexType,
std::index_sequence<Is...>> {
385 using type = extents<IndexType, (static_cast<void>(Is), dynamic_extent)...>;
395template <
class IndexType, std::
size_t Rank>
396class dextents_helper<IndexType, std::integral_constant<std::size_t, Rank>>
397 :
public dextents_helper<IndexType, std::make_index_sequence<Rank>> {};
406template <
typename IndexType, std::
size_t Rank>
407using dextents =
typename extents_detail::dextents_helper<IndexType, std::integral_constant<std::size_t, Rank>>::type;
421template <
typename IndexType,
std::size_t... Extents>
424namespace extents_detail {
441 template <
typename... Integrals>
444 constexpr auto operator()(Integrals&&... extents_values)
const noexcept
A fixed-size array of T objects.
Definition array.hpp:77
represents a multidimensional index space
Definition extents.hpp:72
constexpr extents(extents< OtherIndexType, OtherExtents... > const &source_extents) noexcept
Construct an extents object with the same set of extents as the source extents object.
Definition extents.hpp:256
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
IndexType index_type
The specified index type for the extents.
Definition extents.hpp:108
constexpr extents(OtherIndexTypes... exts) noexcept
Construct an extents object with the specified list of dynamic extents.
Definition extents.hpp:214
constexpr extents() noexcept
Construct an extents object with all the dynamic extents set to zero, if any.
Definition extents.hpp:282
std::make_unsigned_t< index_type > size_type
An unsigned type for representing an index into a dimension.
Definition extents.hpp:110
constexpr extents(span< OtherIndexType, rank_dynamic()> exts) noexcept
Construct an extents object with the specified list of extents.
Definition extents.hpp:154
typename extent_sequence_type::rank_type rank_type
The type of the rank.
Definition extents.hpp:112
constexpr extents(span< OtherIndexType, N > exts) noexcept
Construct an extents object with the specified list of extents.
Definition extents.hpp:137
constexpr extents(array< OtherIndexType, N > const &exts) noexcept
Construct an extents object with the specified list of extents.
Definition extents.hpp:196
constexpr extents(array< OtherIndexType, rank_dynamic()> const &exts) noexcept
Construct an extents object with the specified list of extents.
Definition extents.hpp:173
friend constexpr auto operator!=(extents const &lhs, extents< OtherIndexType, OtherExtents... > const &rhs) noexcept -> bool
Compare two extents objects to see if they have different values.
Definition extents.hpp:356
#define ARENE_CPP14_INLINE_VARIABLE(type, name)
Emulates C++17's inline variable declarations for function objects.
Definition cpp14_inline.hpp:69
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 value_type value
Definition integral_constant.hpp:34
static constexpr auto max() noexcept -> T
The maximum finite value.
Definition numeric_limits.hpp:230
Definition accumulate.hpp:37
constexpr std::integral_constant< typename mdspan< ElementType, Extents, LayoutPolicy, AccessorPolicy >::rank_type, Extents::rank()> mdspan< ElementType, Extents, LayoutPolicy, AccessorPolicy >::rank
Get the number of dimensions in the extents.
Definition mdspan.hpp:724
typename extents_detail::dextents_helper< IndexType, std::integral_constant< std::size_t, Rank > >::type dextents
Backport of std::dextents from C++23, a type representing the extents of a multidimensional array wit...
Definition extents.hpp:407
constexpr bool all_of_v
Trait which tests if every value in a parameter pack is true .
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 std::integral_constant< typename mdspan< ElementType, Extents, LayoutPolicy, AccessorPolicy >::rank_type, Extents::rank_dynamic()> mdspan< ElementType, Extents, LayoutPolicy, AccessorPolicy >::rank_dynamic
Get the number of dimensions with dynamic extent.
Definition mdspan.hpp:735
Definition accumulate.hpp:36
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 make_unsigned< Type >::type make_unsigned_t
A type alias for the equivalent unsigned type for integral and enumeration types other than bool.
Definition make_unsigned.hpp:252
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24
Provides backports of the safe integer comparison functions from C++20.
Provides the all_of_v<bool...> trait.