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/extent.hpp>
16#include <etl/_type_traits/is_array.hpp>
17#include <etl/_type_traits/is_constructible.hpp>
18#include <etl/_type_traits/is_convertible.hpp>
19#include <etl/_type_traits/is_default_constructible.hpp>
20#include <etl/_type_traits/is_nothrow_constructible.hpp>
21#include <etl/_type_traits/is_object.hpp>
22#include <etl/_type_traits/is_pointer.hpp>
23#include <etl/_type_traits/rank.hpp>
24#include <etl/_type_traits/remove_all_extents.hpp>
25#include <etl/_type_traits/remove_cv.hpp>
26#include <etl/_type_traits/remove_pointer.hpp>
27#include <etl/_type_traits/remove_reference.hpp>
28#include <etl/_utility/index_sequence.hpp>
29#include <etl/_utility/move.hpp>
41 using extents_type = Extents;
42 using layout_type = LayoutPolicy;
43 using accessor_type = AccessorPolicy;
44 using mapping_type =
typename layout_type::
template mapping<extents_type>;
45 using element_type = ElementType;
46 using value_type = remove_cv_t<element_type>;
47 using index_type =
typename extents_type::index_type;
48 using size_type =
typename extents_type::size_type;
49 using rank_type =
typename extents_type::rank_type;
50 using data_handle_type =
typename accessor_type::data_handle_type;
51 using reference =
typename accessor_type::reference;
55 return extents_type::rank();
60 return extents_type::rank_dynamic();
65 return Extents::static_extent(r);
76 and is_default_constructible_v<data_handle_type>
77 and is_default_constructible_v<mapping_type>
78 and is_default_constructible_v<accessor_type>)
86 template <
typename... OtherIndexTypes>
87 requires((is_convertible_v<OtherIndexTypes, index_type>
and ...)
88 and (is_nothrow_constructible_v<index_type, OtherIndexTypes>
and ...)
90 and is_constructible_v<mapping_type, extents_type>
91 and is_default_constructible_v<accessor_type>)
92 explicit constexpr mdspan(data_handle_type ptr, OtherIndexTypes... exts)
93 : _ptr(
etl::move(ptr))
94 , _map(extents_type(
static_cast<index_type>(
etl::move(exts))...))
99 template <
typename OtherIndexType, size_t N>
100 requires(is_convertible_v<OtherIndexType
const&, index_type>
101 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>
103 and is_constructible_v<mapping_type, extents_type>
104 and is_default_constructible_v<accessor_type>)
113 template <
typename OtherIndexType, size_t N>
114 requires(is_convertible_v<OtherIndexType
const&, index_type>
115 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>
117 and is_constructible_v<mapping_type, extents_type>
118 and is_default_constructible_v<accessor_type>)
127 constexpr mdspan(data_handle_type ptr, extents_type
const& ext)
128 requires(is_constructible_v<mapping_type, mapping_type
const&>
and is_default_constructible_v<accessor_type>)
129 : _ptr(
etl::move(ptr))
135 constexpr mdspan(data_handle_type ptr, mapping_type
const& m)
136 requires(is_default_constructible_v<accessor_type>)
137 : _ptr(
etl::move(ptr))
143 constexpr mdspan(data_handle_type ptr, mapping_type
const& m, accessor_type
const& a)
144 : _ptr(
etl::move(ptr))
150 template <
typename OtherElement,
typename OtherExtents,
typename OtherLayout,
typename OtherAccessor>
151 requires((is_constructible_v<mapping_type,
typename OtherLayout::
template mapping<OtherExtents>
const&>
152 and is_constructible_v<accessor_type, OtherAccessor
const&>))
156 ))
constexpr mdspan(
mdspan<OtherElement, OtherExtents, OtherLayout, OtherAccessor>
const&
other)
157 : _ptr(
other.data_handle())
161 static_assert(is_constructible_v<extents_type, OtherExtents>);
162 static_assert(is_constructible_v<data_handle_type,
typename OtherAccessor::data_handle_type
const&>);
168 template <
typename... OtherIndexTypes>
170 (is_convertible_v<OtherIndexTypes, index_type> && ...)
171 and (is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...)
172 and sizeof...(OtherIndexTypes) ==
rank()
174 [[nodiscard]]
constexpr auto operator()(OtherIndexTypes... indices)
const -> reference
176 auto const idx =
static_cast<
etl::size_t>(_map(extents_type::index_cast(
etl::move(indices))...));
177 return _acc.access(_ptr, idx);
180#if defined(__cpp_multidimensional_subscript)
181 template <
typename... OtherIndexTypes>
183 (is_convertible_v<OtherIndexTypes, index_type> && ...)
184 and (is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...)
185 and sizeof...(OtherIndexTypes) ==
rank()
187 [[nodiscard]]
constexpr auto operator[](OtherIndexTypes... indices)
const -> reference
189 return (*
this)(
etl::move(indices)...);
193 template <
typename OtherIndexType>
195 is_convertible_v<OtherIndexType
const&, index_type>
196 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>
198 [[nodiscard]]
constexpr auto operator[](span<OtherIndexType,
rank()> indices)
const -> reference
200 return [&]<size_t... Is>(index_sequence<Is...> ) -> reference {
201 return (*
this)(indices[Is]...);
202 }(make_index_sequence<
rank()>{});
205 template <
typename OtherIndexType>
207 is_convertible_v<OtherIndexType
const&, index_type>
208 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>
212 return (*
this)[
etl::span{indices}];
230 return _map.extents();
234 return _map.stride(r);
238 return size() == size_type{};
247 return _map.is_unique();
251 return _map.is_exhaustive();
255 return _map.is_strided();
260 return mapping_type::is_always_unique();
264 return mapping_type::is_always_exhaustive();
268 return mapping_type::is_always_strided();
277template <
typename CArray>
278 requires(is_array_v<CArray> && rank_v<CArray> == 1)
281template <
typename Pointer>
282 requires(is_pointer_v<remove_reference_t<Pointer>>)
285template <
typename ElementType,
typename... Integrals>
286 requires((is_convertible_v<Integrals, size_t> && ...) &&
sizeof...(Integrals) > 0)
287explicit mdspan(ElementType*, Integrals...) ->
mdspan<ElementType, dextents<size_t,
sizeof...(Integrals)>>;
289template <
typename ElementType,
typename IndexType, size_t... ExtentsPack>
293template <
typename ElementType,
typename MappingType>
297template <
typename MappingType,
typename AccessorType>
298mdspan(
typename AccessorType::data_handle_type
const&, MappingType
const&, AccessorType
const&) ->
mdspan<
305template <
typename ElementType,
typename Extents,
typename LayoutPolicy,
typename Container>
308template <
class ElementType,
class Extents,
class Layout,
class Container>
310 typename decltype(declval<
mdarray<ElementType, Extents, Layout, Container>>().to_mdspan())::
element_type,
311 typename decltype(declval<
mdarray<ElementType, Extents, Layout, Container>>().to_mdspan())::
extens_type,
312 typename decltype(declval<
mdarray<ElementType, Extents, Layout, Container>>().to_mdspan())::
layout_type,
313 typename decltype(declval<
mdarray<ElementType, Extents, Layout, Container>>().to_mdspan())::
accessor_type
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(CArray &) -> mdspan< remove_all_extents_t< CArray >, extents< size_t, extent_v< CArray, 0 > > >
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)> >
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(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 mdarray.hpp:26
static constexpr auto is_always_unique() -> bool
Definition mdspan.hpp:258
constexpr mdspan(data_handle_type ptr, mapping_type const &m)
Definition mdspan.hpp:135
static constexpr auto rank() noexcept -> rank_type
Definition mdspan.hpp:53
constexpr auto accessor() const noexcept -> accessor_type const &
Definition mdspan.hpp:223
constexpr auto operator()(OtherIndexTypes... indices) const -> reference
Definition mdspan.hpp:174
constexpr mdspan(data_handle_type ptr, extents_type const &ext)
Definition mdspan.hpp:127
constexpr auto stride(rank_type r) const -> index_type
Definition mdspan.hpp:232
constexpr auto operator[](span< OtherIndexType, rank()> indices) const -> reference
Definition mdspan.hpp:198
OtherAccessor const & other
Definition mdspan.hpp:158
constexpr auto operator[](array< OtherIndexType, rank()> const &indices) const -> reference
Definition mdspan.hpp:210
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
constexpr auto mapping() const noexcept -> mapping_type const &
Definition mdspan.hpp:219
constexpr mdspan(data_handle_type ptr, mapping_type const &m, accessor_type const &a)
Definition mdspan.hpp:143
explicit(N !=rank_dynamic()) const expr mdspan(data_handle_type p
constexpr auto extent(rank_type r) const noexcept -> index_type
Definition mdspan.hpp:68
span< OtherIndexType, N > exts
Definition mdspan.hpp:107
constexpr auto empty() const noexcept -> bool
Definition mdspan.hpp:236
constexpr auto data_handle() const noexcept -> data_handle_type const &
Definition mdspan.hpp:215
array< OtherIndexType, N > const & exts
Definition mdspan.hpp:121
static constexpr auto rank_dynamic() noexcept -> rank_type
Definition mdspan.hpp:58
static constexpr auto is_always_exhaustive() -> bool
Definition mdspan.hpp:262
constexpr auto is_unique() const -> bool
Definition mdspan.hpp:245
constexpr mdspan(mdspan &&rhs)=default
constexpr auto is_strided() const -> bool
Definition mdspan.hpp:253
constexpr auto is_exhaustive() const -> bool
Definition mdspan.hpp:249
constexpr mdspan(data_handle_type ptr, OtherIndexTypes... exts)
Definition mdspan.hpp:92
static constexpr auto static_extent(rank_type r) noexcept -> size_t
Definition mdspan.hpp:63
constexpr auto extents() const noexcept -> extents_type const &
Definition mdspan.hpp:228
constexpr auto size() const noexcept -> size_type
Definition mdspan.hpp:240
static constexpr auto is_always_strided() -> bool
Definition mdspan.hpp:266
constexpr mdspan(mdspan const &rhs)=default