4#ifndef TETL_MDSPAN_MDSPAN_HPP
5#define TETL_MDSPAN_MDSPAN_HPP
7#include <etl/_config/all.hpp>
9#include <etl/_array/array.hpp>
10#include <etl/_contracts/check.hpp>
11#include <etl/_mdspan/default_accessor.hpp>
12#include <etl/_mdspan/layout_left.hpp>
13#include <etl/_mdspan/layout_right.hpp>
14#include <etl/_span/span.hpp>
15#include <etl/_type_traits/bool_constant.hpp>
16#include <etl/_type_traits/extent.hpp>
17#include <etl/_type_traits/is_array.hpp>
18#include <etl/_type_traits/is_constructible.hpp>
19#include <etl/_type_traits/is_convertible.hpp>
20#include <etl/_type_traits/is_default_constructible.hpp>
21#include <etl/_type_traits/is_nothrow_constructible.hpp>
22#include <etl/_type_traits/is_object.hpp>
23#include <etl/_type_traits/is_pointer.hpp>
24#include <etl/_type_traits/rank.hpp>
25#include <etl/_type_traits/remove_all_extents.hpp>
26#include <etl/_type_traits/remove_cv.hpp>
27#include <etl/_type_traits/remove_pointer.hpp>
28#include <etl/_type_traits/remove_reference.hpp>
29#include <etl/_utility/index_sequence.hpp>
30#include <etl/_utility/move.hpp>
42 using extents_type = Extents;
43 using layout_type = LayoutPolicy;
44 using accessor_type = AccessorPolicy;
45 using mapping_type =
typename layout_type::
template mapping<extents_type>;
46 using element_type = ElementType;
47 using value_type = remove_cv_t<element_type>;
48 using index_type =
typename extents_type::index_type;
49 using size_type =
typename extents_type::size_type;
50 using rank_type =
typename extents_type::rank_type;
51 using data_handle_type =
typename accessor_type::data_handle_type;
52 using reference =
typename accessor_type::reference;
56 return extents_type::rank();
61 return extents_type::rank_dynamic();
66 return Extents::static_extent(r);
77 and is_default_constructible_v<data_handle_type>
78 and is_default_constructible_v<mapping_type>
79 and is_default_constructible_v<accessor_type>)
87 template <
typename... OtherIndexTypes>
88 requires((is_convertible_v<OtherIndexTypes, index_type>
and ...)
89 and (is_nothrow_constructible_v<index_type, OtherIndexTypes>
and ...)
91 and is_constructible_v<mapping_type, extents_type>
92 and is_default_constructible_v<accessor_type>)
93 explicit constexpr mdspan(data_handle_type ptr, OtherIndexTypes... exts)
94 : _ptr(
etl::move(ptr))
95 , _map(extents_type(
static_cast<index_type>(
etl::move(exts))...))
100 template <
typename OtherIndexType, size_t N>
101 requires(is_convertible_v<OtherIndexType
const&, index_type>
102 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>
104 and is_constructible_v<mapping_type, extents_type>
105 and is_default_constructible_v<accessor_type>)
114 template <
typename OtherIndexType, size_t N>
115 requires(is_convertible_v<OtherIndexType
const&, index_type>
116 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>
118 and is_constructible_v<mapping_type, extents_type>
119 and is_default_constructible_v<accessor_type>)
128 constexpr mdspan(data_handle_type ptr, extents_type
const& ext)
129 requires(is_constructible_v<mapping_type, mapping_type
const&>
and is_default_constructible_v<accessor_type>)
130 : _ptr(
etl::move(ptr))
136 constexpr mdspan(data_handle_type ptr, mapping_type
const& m)
137 requires(is_default_constructible_v<accessor_type>)
138 : _ptr(
etl::move(ptr))
144 constexpr mdspan(data_handle_type ptr, mapping_type
const& m, accessor_type
const& a)
145 : _ptr(
etl::move(ptr))
151 template <
typename OtherElement,
typename OtherExtents,
typename OtherLayout,
typename OtherAccessor>
152 requires(is_constructible_v<mapping_type,
typename OtherLayout::
template mapping<OtherExtents>
const&>
153 and is_constructible_v<accessor_type, OtherAccessor
const&>)
158 : _ptr(
other.data_handle())
162 static_assert(is_constructible_v<extents_type, OtherExtents>);
163 static_assert(is_constructible_v<data_handle_type,
typename OtherAccessor::data_handle_type
const&>);
169 template <
typename... OtherIndexTypes>
171 (is_convertible_v<OtherIndexTypes, index_type>
and ...)
172 and (is_nothrow_constructible_v<index_type, OtherIndexTypes>
and ...)
173 and sizeof...(OtherIndexTypes) ==
rank()
175 [[nodiscard]]
constexpr auto operator()(OtherIndexTypes... indices)
const -> reference
177 auto const idx =
static_cast<
etl::size_t>(_map(extents_type::index_cast(
etl::move(indices))...));
178 return _acc.access(_ptr, idx);
181#if defined(__cpp_multidimensional_subscript)
182 template <
typename... OtherIndexTypes>
184 (is_convertible_v<OtherIndexTypes, index_type>
and ...)
185 and (is_nothrow_constructible_v<index_type, OtherIndexTypes>
and ...)
186 and sizeof...(OtherIndexTypes) ==
rank()
188 [[nodiscard]]
constexpr auto operator[](OtherIndexTypes... indices)
const -> reference
190 return (*
this)(
etl::move(indices)...);
194 template <
typename OtherIndexType>
196 is_convertible_v<OtherIndexType
const&, index_type>
197 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>
199 [[nodiscard]]
constexpr auto operator[](span<OtherIndexType,
rank()> indices)
const -> reference
201 return [&]<size_t... Is>(index_sequence<Is...> ) -> reference {
202 return (*
this)(indices[Is]...);
203 }(make_index_sequence<
rank()>{});
206 template <
typename OtherIndexType>
208 is_convertible_v<OtherIndexType
const&, index_type>
209 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>
213 return (*
this)[
etl::span{indices}];
231 return _map.extents();
235 return _map.stride(r);
239 return size() == size_type{};
248 return _map.is_unique();
252 return _map.is_exhaustive();
256 return _map.is_strided();
261 return mapping_type::is_always_unique();
265 return mapping_type::is_always_exhaustive();
269 return mapping_type::is_always_strided();
278template <
typename CArray>
279 requires(is_array_v<CArray>
and rank_v<CArray> == 1)
282template <
typename Pointer>
283 requires(is_pointer_v<remove_reference_t<Pointer>>)
286template <
typename ElementType,
typename... Integrals>
287 requires((is_convertible_v<Integrals, size_t>
and ...)
and sizeof...(Integrals) > 0)
288explicit mdspan(ElementType*, Integrals...) ->
mdspan<ElementType, dextents<size_t,
sizeof...(Integrals)>>;
290template <
typename ElementType,
typename IndexType, size_t... ExtentsPack>
294template <
typename ElementType,
typename MappingType>
298template <
typename MappingType,
typename AccessorType>
299mdspan(
typename AccessorType::data_handle_type
const&, MappingType
const&, AccessorType
const&) ->
mdspan<
306template <
typename ElementType,
typename Extents,
typename LayoutPolicy,
typename Container>
309template <
class ElementType,
class Extents,
class Layout,
class Container>
311 typename decltype(declval<
mdarray<ElementType, Extents, Layout, Container>>().to_mdspan())::
element_type,
312 typename decltype(declval<
mdarray<ElementType, Extents, Layout, Container>>().to_mdspan())::
extens_type,
313 typename decltype(declval<
mdarray<ElementType, Extents, Layout, Container>>().to_mdspan())::
layout_type,
314 typename decltype(declval<
mdarray<ElementType, Extents, Layout, Container>>().to_mdspan())::
accessor_type
320template <
typename T,
typename Extents,
typename Layout,
typename Accessor>
Definition adjacent_find.hpp:9
mdspan(typename AccessorType::data_handle_type const &, MappingType const &, AccessorType const &) -> mdspan< typename AccessorType::element_type, typename MappingType::extents_type, typename MappingType::layout_type, AccessorType >
mdspan(mdarray< ElementType, Extents, Layout, Container >) -> mdspan< typename decltype(declval< mdarray< ElementType, Extents, Layout, Container > >().to_mdspan())::element_type, typename decltype(declval< mdarray< ElementType, Extents, Layout, Container > >().to_mdspan())::extens_type, typename decltype(declval< mdarray< ElementType, Extents, Layout, Container > >().to_mdspan())::layout_type, typename decltype(declval< mdarray< ElementType, Extents, Layout, Container > >().to_mdspan())::accessor_type >
mdspan(ElementType *, Integrals...) -> mdspan< ElementType, dextents< size_t, sizeof...(Integrals)> >
constexpr auto is_mdspan_v
Definition mdspan.hpp:324
mdspan(Pointer &&) -> mdspan< remove_pointer_t< remove_reference_t< Pointer > >, extents< size_t > >
mdspan(ElementType *, MappingType const &) -> mdspan< ElementType, typename MappingType::extents_type, typename MappingType::layout_type >
mdspan(CArray &) -> mdspan< remove_all_extents_t< CArray >, extents< size_t, extent_v< CArray, 0 > > >
mdspan(ElementType *, extents< IndexType, ExtentsPack... > const &) -> mdspan< ElementType, extents< IndexType, ExtentsPack... > >
A container that encapsulates fixed size arrays.
Definition array.hpp:49
Definition default_accessor.hpp:13
Definition extents.hpp:23
Definition mdspan.hpp:318
Definition mdarray.hpp:26
static constexpr auto is_always_unique() -> bool
Definition mdspan.hpp:259
constexpr mdspan(data_handle_type ptr, mapping_type const &m)
Definition mdspan.hpp:136
static constexpr auto rank() noexcept -> rank_type
Definition mdspan.hpp:54
constexpr auto accessor() const noexcept -> accessor_type const &
Definition mdspan.hpp:224
constexpr mdspan(data_handle_type ptr, extents_type const &ext)
Definition mdspan.hpp:128
constexpr auto stride(rank_type r) const -> index_type
Definition mdspan.hpp:233
constexpr auto operator[](span< OtherIndexType, rank()> indices) const -> reference
Definition mdspan.hpp:199
OtherAccessor const & other
Definition mdspan.hpp:159
constexpr auto operator[](array< OtherIndexType, rank()> const &indices) const -> reference
Definition mdspan.hpp:211
constexpr mdspan(data_handle_type ptr, OtherIndexTypes... exts)
Definition mdspan.hpp:93
constexpr auto mapping() const noexcept -> mapping_type const &
Definition mdspan.hpp:220
constexpr mdspan(data_handle_type ptr, mapping_type const &m, accessor_type const &a)
Definition mdspan.hpp:144
explicit(N !=rank_dynamic()) const expr mdspan(data_handle_type p
constexpr auto extent(rank_type r) const noexcept -> index_type
Definition mdspan.hpp:69
span< OtherIndexType, N > exts
Definition mdspan.hpp:108
constexpr auto empty() const noexcept -> bool
Definition mdspan.hpp:237
constexpr auto data_handle() const noexcept -> data_handle_type const &
Definition mdspan.hpp:216
array< OtherIndexType, N > const & exts
Definition mdspan.hpp:122
explicit(not is_convertible_v< typename OtherLayout::template mapping< OtherExtents > const &, mapping_type > or not is_convertible_v< OtherAccessor const &, accessor_type >) const expr mdspan(mdspan< OtherElement
static constexpr auto rank_dynamic() noexcept -> rank_type
Definition mdspan.hpp:59
static constexpr auto is_always_exhaustive() -> bool
Definition mdspan.hpp:263
constexpr auto is_unique() const -> bool
Definition mdspan.hpp:246
constexpr auto operator()(OtherIndexTypes... indices) const -> reference
Definition mdspan.hpp:175
constexpr mdspan(mdspan &&rhs)=default
constexpr auto is_strided() const -> bool
Definition mdspan.hpp:254
constexpr auto is_exhaustive() const -> bool
Definition mdspan.hpp:250
static constexpr auto static_extent(rank_type r) noexcept -> size_t
Definition mdspan.hpp:64
constexpr auto extents() const noexcept -> extents_type const &
Definition mdspan.hpp:229
constexpr auto size() const noexcept -> size_type
Definition mdspan.hpp:241
static constexpr auto is_always_strided() -> bool
Definition mdspan.hpp:267
constexpr mdspan(mdspan const &rhs)=default