tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
layout_stride.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_MDSPAN_LAYOUT_STRIDE_HPP
4#define TETL_MDSPAN_LAYOUT_STRIDE_HPP
5
11#include <etl/_span/span.hpp>
16
17namespace etl {
18
19template <typename Extents>
21 using extents_type = Extents;
22 using index_type = typename extents_type::index_type;
23 using size_type = typename extents_type::size_type;
24 using rank_type = typename extents_type::rank_type;
26
27private:
28 static constexpr auto rank = extents_type::rank();
29
30public:
31 constexpr mapping() noexcept = default;
32 constexpr mapping(mapping const&) noexcept = default;
33
34 template <typename OtherIndexType>
35 requires(is_convertible_v<OtherIndexType const&, index_type>
36 and is_nothrow_constructible_v<index_type, OtherIndexType const&>)
37 constexpr mapping(extents_type const& ext, span<OtherIndexType, rank> s) noexcept
38 : _extents(ext)
39 , _strides([&]<size_t... Is>(index_sequence<Is...> /*seq*/) {
40 return array{static_cast<index_type>(etl::as_const(s[Is]))...};
42 {
43 }
44
45 template <typename OtherIndexType>
47 constexpr mapping(extents_type const& ext, array<OtherIndexType, rank> const& s) noexcept
48 : mapping(ext, span(s))
49 {
50 }
51
52 template <typename StridedLayoutMapping>
53 constexpr explicit(false /* see description */) mapping(StridedLayoutMapping const&) noexcept;
54
55 constexpr auto operator=(mapping const&) noexcept -> mapping& = default;
56
57 [[nodiscard]] constexpr auto required_span_size() const noexcept -> index_type;
58 [[nodiscard]] constexpr auto extents() const noexcept -> extents_type const& { return _extents; }
59 [[nodiscard]] constexpr auto strides() const noexcept -> array<index_type, rank> { return _strides; }
60 [[nodiscard]] constexpr auto stride(rank_type i) const noexcept -> index_type
61 {
62 TETL_PRECONDITION(i < extents_type::rank());
63 return _strides[i];
64 }
65
66 template <typename... Indices>
67 requires(
68 (sizeof...(Indices) == rank) //
71 )
72 [[nodiscard]] constexpr auto operator()(Indices... is) const noexcept -> index_type
73 {
74 return [&]<size_t... Is>(index_sequence<Is...> /*seq*/) {
75 return static_cast<index_type>(((static_cast<index_type>(is) * _strides[Is]) + ... + index_type(0)));
76 }(index_sequence_for<Indices...>{});
77 }
78
79 [[nodiscard]] static constexpr auto is_always_unique() noexcept -> bool { return true; }
80 [[nodiscard]] static constexpr auto is_always_strided() noexcept -> bool { return true; }
81 [[nodiscard]] static constexpr auto is_always_exhaustive() noexcept -> bool { return false; }
82
83 [[nodiscard]] static constexpr auto is_unique() noexcept -> bool { return true; }
84 [[nodiscard]] static constexpr auto is_strided() noexcept -> bool { return true; }
85 [[nodiscard]] constexpr auto is_exhaustive() const noexcept -> bool;
86
87 template <typename OtherMapping>
88 friend constexpr auto operator==(mapping const&, OtherMapping const&) noexcept -> bool;
89
90private:
93};
94
95} // namespace etl
96
97#endif // TETL_MDSPAN_LAYOUT_STRIDE_HPP
#define TETL_NO_UNIQUE_ADDRESS
Definition attributes.hpp:41
#define TETL_PRECONDITION(...)
Definition check.hpp:16
Definition adjacent_find.hpp:8
constexpr auto as_const(T &t) noexcept -> add_const_t< T > &
Forms lvalue reference to const type of t.
Definition as_const.hpp:12
etl::make_index_sequence< sizeof...(T)> index_sequence_for
Definition index_sequence.hpp:18
etl::make_integer_sequence< etl::size_t, Size > make_index_sequence
Definition index_sequence.hpp:15
etl::integer_sequence< etl::size_t, Ints... > index_sequence
Definition index_sequence.hpp:12
span(c_array< Type, Extent > &) -> span< Type, Extent >
constexpr bool is_nothrow_constructible_v
Definition is_nothrow_constructible.hpp:50
constexpr bool is_convertible_v
Definition is_convertible.hpp:46
A container that encapsulates fixed size arrays.
Definition array.hpp:48
Definition layout_stride.hpp:20
constexpr mapping() noexcept=default
typename extents_type::rank_type rank_type
Definition layout_stride.hpp:24
constexpr auto strides() const noexcept -> array< index_type, rank >
Definition layout_stride.hpp:59
typename extents_type::index_type index_type
Definition layout_stride.hpp:22
Extents extents_type
Definition layout_stride.hpp:21
static constexpr auto is_always_exhaustive() noexcept -> bool
Definition layout_stride.hpp:81
constexpr auto is_exhaustive() const noexcept -> bool
constexpr auto operator=(mapping const &) noexcept -> mapping &=default
static constexpr auto is_always_strided() noexcept -> bool
Definition layout_stride.hpp:80
static constexpr auto is_strided() noexcept -> bool
Definition layout_stride.hpp:84
constexpr mapping(extents_type const &ext, array< OtherIndexType, rank > const &s) noexcept
Definition layout_stride.hpp:47
constexpr auto stride(rank_type i) const noexcept -> index_type
Definition layout_stride.hpp:60
static constexpr auto is_always_unique() noexcept -> bool
Definition layout_stride.hpp:79
typename extents_type::size_type size_type
Definition layout_stride.hpp:23
layout_stride layout_type
Definition layout_stride.hpp:25
static constexpr auto is_unique() noexcept -> bool
Definition layout_stride.hpp:83
constexpr auto extents() const noexcept -> extents_type const &
Definition layout_stride.hpp:58
constexpr auto required_span_size() const noexcept -> index_type
Definition layout.hpp:18
If Type is an array type, provides the member constant value equal to the number of dimensions of the...
Definition rank.hpp:16
A non-owning view over a contiguous sequence of objects.
Definition span.hpp:83