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