4#ifndef TETL_MDSPAN_LAYOUT_STRIDE_HPP
5#define TETL_MDSPAN_LAYOUT_STRIDE_HPP
7#include <etl/_array/array.hpp>
8#include <etl/_contracts/check.hpp>
9#include <etl/_mdspan/extents.hpp>
10#include <etl/_mdspan/is_extents.hpp>
11#include <etl/_mdspan/layout.hpp>
12#include <etl/_span/span.hpp>
13#include <etl/_type_traits/is_convertible.hpp>
14#include <etl/_type_traits/is_nothrow_constructible.hpp>
15#include <etl/_utility/as_const.hpp>
16#include <etl/_utility/index_sequence.hpp>
20template <
typename Extents>
22 using extents_type = Extents;
23 using index_type =
typename extents_type::index_type;
24 using size_type =
typename extents_type::size_type;
25 using rank_type =
typename extents_type::rank_type;
29 static constexpr auto rank = extents_type::rank();
33 constexpr mapping(mapping
const&)
noexcept =
default;
35 template <
typename OtherIndexType>
36 requires(is_convertible_v<OtherIndexType
const&, index_type>
37 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>)
38 constexpr mapping(extents_type
const& ext, span<OtherIndexType, rank> s)
noexcept
40 , _strides([&]<size_t... Is>(index_sequence<Is...> ) {
41 return array{
static_cast<index_type>(
etl::as_const(s[Is]))...};
42 }(make_index_sequence<rank>()))
46 template <
typename OtherIndexType>
48 is_convertible_v<OtherIndexType
const&, index_type>
49 and is_nothrow_constructible_v<index_type, OtherIndexType
const&>
51 constexpr mapping(extents_type
const& ext,
array<OtherIndexType, rank>
const& s)
noexcept
52 : mapping(ext, span(s))
56 template <
typename StridedLayoutMapping>
57 constexpr explicit(
false )
mapping(StridedLayoutMapping
const&)
noexcept;
59 constexpr auto operator=(mapping
const&)
noexcept -> mapping& =
default;
62 [[nodiscard]]
constexpr auto extents()
const noexcept -> extents_type
const&
66 [[nodiscard]]
constexpr auto strides()
const noexcept ->
array<index_type, rank>
70 [[nodiscard]]
constexpr auto stride(rank_type i)
const noexcept -> index_type
72 TETL_PRECONDITION(i < extents_type::rank());
76 template <
typename... Indices>
78 (
sizeof...(Indices) == rank)
79 and (is_convertible_v<Indices, index_type>
and ...)
80 and (is_nothrow_constructible_v<index_type, Indices>
and ...)
82 [[nodiscard]]
constexpr auto operator()(Indices... is)
const noexcept -> index_type
84 return [&]<size_t... Is>(index_sequence<Is...> ) {
85 return static_cast<index_type>(((
static_cast<index_type>(is) * _strides[Is]) + ... + index_type(0)));
86 }(index_sequence_for<Indices...>{});
102 [[nodiscard]]
static constexpr auto is_unique()
noexcept ->
bool
106 [[nodiscard]]
static constexpr auto is_strided()
noexcept ->
bool
112 template <
typename OtherMapping>
113 friend constexpr auto operator==(mapping
const&, OtherMapping
const&)
noexcept ->
bool;
116 TETL_NO_UNIQUE_ADDRESS extents_type _extents{};
117 TETL_NO_UNIQUE_ADDRESS
array<index_type, rank> _strides{};
Definition adjacent_find.hpp:9
A container that encapsulates fixed size arrays.
Definition array.hpp:49
constexpr mapping() noexcept=default
constexpr auto strides() const noexcept -> array< index_type, rank >
Definition layout_stride.hpp:66
static constexpr auto is_always_exhaustive() noexcept -> bool
Definition layout_stride.hpp:97
constexpr auto is_exhaustive() const noexcept -> bool
constexpr auto operator=(mapping const &) noexcept -> mapping &=default
constexpr auto operator()(Indices... is) const noexcept -> index_type
Definition layout_stride.hpp:82
static constexpr auto is_always_strided() noexcept -> bool
Definition layout_stride.hpp:93
static constexpr auto is_strided() noexcept -> bool
Definition layout_stride.hpp:106
friend constexpr auto operator==(mapping const &, OtherMapping const &) noexcept -> bool
constexpr auto stride(rank_type i) const noexcept -> index_type
Definition layout_stride.hpp:70
static constexpr auto is_always_unique() noexcept -> bool
Definition layout_stride.hpp:89
constexpr mapping(extents_type const &ext, span< OtherIndexType, rank > s) noexcept
Definition layout_stride.hpp:38
constexpr mapping(extents_type const &ext, array< OtherIndexType, rank > const &s) noexcept
Definition layout_stride.hpp:51
static constexpr auto is_unique() noexcept -> bool
Definition layout_stride.hpp:102
constexpr explicit(false) mapping(StridedLayoutMapping const &) noexcept
constexpr mapping(mapping const &) noexcept=default
constexpr auto extents() const noexcept -> extents_type const &
Definition layout_stride.hpp:62
constexpr auto required_span_size() const noexcept -> index_type