tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
layout_right.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_MDSPAN_LAYOUT_RIGHT_HPP
4#define TETL_MDSPAN_LAYOUT_RIGHT_HPP
5
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
27 // constructors
28 constexpr mapping() noexcept = default;
29 constexpr mapping(mapping const&) noexcept = default;
30
31 constexpr mapping(extents_type const& ext) noexcept
32 : _extents{ext}
33 {
34 }
35
36 template <typename OtherExtents>
39 mapping(mapping<OtherExtents> const& other) noexcept
40 : _extents{other.extents()}
41 {
42 }
43
44 template <typename OtherExtents>
45 requires(extents_type::rank() <= 1) && is_constructible_v<extents_type, OtherExtents>
47 mapping(layout_left::mapping<OtherExtents> const& other) noexcept
48 : _extents{other.extents()}
49 {
50 }
51
52 template <typename OtherExtents>
53 constexpr explicit(extents_type::rank() > 0) mapping(layout_stride::mapping<OtherExtents> const&) noexcept;
54
55 constexpr auto operator=(mapping const&) noexcept -> mapping& = default;
56
57 // observers
58 [[nodiscard]] constexpr auto extents() const noexcept -> extents_type const& { return _extents; }
59
60 [[nodiscard]] constexpr auto required_span_size() const noexcept -> index_type
61 {
62 return static_cast<index_type>(extents().fwd_prod_of_extents(extents_type::rank()));
63 }
64
65 template <typename... Indices>
66 requires(sizeof...(Indices) == extents_type::rank()) and (is_convertible_v<Indices, index_type> and ...)
68 [[nodiscard]] constexpr auto operator()(Indices... indices) const noexcept -> index_type
69 {
70 return [&]<size_t... Is>(index_sequence<Is...> /*seq*/) {
71 return static_cast<index_type>(((static_cast<index_type>(indices) * stride(Is)) + ... + 0));
72 }(index_sequence_for<Indices...>{});
73 }
74
75 [[nodiscard]] constexpr auto stride(rank_type r) const noexcept -> index_type
76 requires(extents_type::rank() > 0)
77 {
78 TETL_PRECONDITION(r < extents_type::rank());
79 return static_cast<index_type>(_extents.rev_prod_of_extents(r));
80 }
81
82 [[nodiscard]] static constexpr auto is_always_unique() noexcept -> bool { return true; }
83 [[nodiscard]] static constexpr auto is_always_exhaustive() noexcept -> bool { return true; }
84 [[nodiscard]] static constexpr auto is_always_strided() noexcept -> bool { return true; }
85
86 [[nodiscard]] static constexpr auto is_unique() noexcept -> bool { return true; }
87 [[nodiscard]] static constexpr auto is_exhaustive() noexcept -> bool { return true; }
88 [[nodiscard]] static constexpr auto is_strided() noexcept -> bool { return true; }
89
90 template <typename OtherExtents>
91 friend constexpr auto operator==(mapping const& lhs, mapping<OtherExtents> const& rhs) noexcept -> bool
92 {
93 return lhs.extents() == rhs.extents();
94 }
95
96private:
97 // template <typename... SliceSpecifiers>
98 // [[nodiscard]] constexpr auto submdspan_mapping_impl(SliceSpecifiers... slices) const
99 // {
100 // auto sub_ext = etl::submdspan_extents(extents(), slices...);
101 // using SubExtents = decltype(sub_ext);
102 // static_assert(sizeof(SubExtents) > 0);
103
104 // // auto sub_strides = {};
105
106 // if constexpr (Extents::rank() == 0) {
107 // return etl::submdspan_mapping_result {*this, 0};
108 // } else {
109 // static_assert(etl::always_false<SliceSpecifiers...>);
110 // }
111 // }
112
113 // template <typename... SliceSpecifiers>
114 // friend constexpr auto submdspan_mapping(mapping const& src, SliceSpecifiers... slices)
115 // {
116 // return src.submdspan_mapping_impl(slices...);
117 // }
118
120};
121
122} // namespace etl
123
124#endif // TETL_MDSPAN_LAYOUT_RIGHT_HPP
#define TETL_NO_UNIQUE_ADDRESS
Definition attributes.hpp:41
#define TETL_PRECONDITION(...)
Definition check.hpp:16
Definition adjacent_find.hpp:8
constexpr bool is_constructible_v
Definition is_constructible.hpp:24
etl::make_index_sequence< sizeof...(T)> index_sequence_for
Definition index_sequence.hpp:18
etl::integer_sequence< etl::size_t, Ints... > index_sequence
Definition index_sequence.hpp:12
constexpr bool is_nothrow_constructible_v
Definition is_nothrow_constructible.hpp:50
constexpr bool is_convertible_v
Definition is_convertible.hpp:46
Definition layout_left.hpp:19
Definition layout_right.hpp:20
constexpr auto operator()(Indices... indices) const noexcept -> index_type
Definition layout_right.hpp:68
constexpr mapping() noexcept=default
typename extents_type::rank_type rank_type
Definition layout_right.hpp:24
typename extents_type::index_type index_type
Definition layout_right.hpp:22
static constexpr auto is_exhaustive() noexcept -> bool
Definition layout_right.hpp:87
Extents extents_type
Definition layout_right.hpp:21
static constexpr auto is_always_exhaustive() noexcept -> bool
Definition layout_right.hpp:83
friend constexpr auto operator==(mapping const &lhs, mapping< OtherExtents > const &rhs) noexcept -> bool
Definition layout_right.hpp:91
static constexpr auto is_always_strided() noexcept -> bool
Definition layout_right.hpp:84
static constexpr auto is_strided() noexcept -> bool
Definition layout_right.hpp:88
static constexpr auto is_always_unique() noexcept -> bool
Definition layout_right.hpp:82
typename extents_type::size_type size_type
Definition layout_right.hpp:23
constexpr auto stride(rank_type r) const noexcept -> index_type requires(extents_type::rank() > 0)
Definition layout_right.hpp:75
layout_right layout_type
Definition layout_right.hpp:25
static constexpr auto is_unique() noexcept -> bool
Definition layout_right.hpp:86
constexpr auto extents() const noexcept -> extents_type const &
Definition layout_right.hpp:58
constexpr auto required_span_size() const noexcept -> index_type
Definition layout_right.hpp:60
constexpr explicit(extents_type::rank() > 0) mapping(layout_stride constexpr auto operator=(mapping const &) noexcept -> mapping &=default
Definition layout.hpp:13
Definition layout_stride.hpp:20