36template <
typename T,
size_t Extent = std::dynamic_extent>
49 static constexpr size_t extent = Extent;
54 requires(Extent ==
std::dynamic_extent || Extent == 0)
61 template <std::contiguous_iterator It>
62 constexpr explicit(
extent != std::dynamic_extent)
66 template <std::contiguous_iterator It, std::sized_sentinel_for<It> End>
67 requires(!std::is_convertible_v<End, size_type>)
68 constexpr explicit(
extent != std::dynamic_extent)
74 template <
size_t ArrayExtent>
75 requires(Extent == std::dynamic_extent || ArrayExtent == Extent)
77 std::type_identity_t<element_type> (&arr)[ArrayExtent],
78 int rotation = 0) noexcept
81 template <
typename Tp,
size_t ArrayExtent>
83 int rotation = 0) noexcept
86 template <
typename Tp,
size_t ArrayExtent>
88 int rotation = 0) noexcept
91 template <
typename OType,
size_t OExtent>
92 requires(Extent == std::dynamic_extent || OExtent == std::dynamic_extent ||
94 constexpr explicit(extent != std::dynamic_extent &&
95 OExtent == std::dynamic_extent)
98 : m_data{other.m_data},
99 m_offset{MakeOffset(other.m_data.size(), other.m_offset + rotation)} {}
101 template <
typename OType,
size_t OExtent>
102 requires(Extent == std::dynamic_extent || OExtent == std::dynamic_extent ||
104 constexpr explicit(extent != std::dynamic_extent &&
107 : m_data{other.m_data}, m_offset{other.m_offset} {}
116 constexpr
std::span<T, Extent> data() const noexcept {
return m_data; }
123 return m_data.size_bytes();
126 constexpr bool empty() const noexcept {
return m_data.empty(); }
132 return m_data[m_offset];
137 return m_data[(m_offset + m_data.size() - 1) % m_data.size()];
142 return m_data[(m_offset + idx) % m_data.size()];
156 : m_obj{obj}, m_idx{idx} {}
204 std::span<T, Extent> m_data;
207 static constexpr size_type MakeOffset(
size_t size,
int rotation) {
212 return rotation % size;
218 return size - (-rotation % size);
225template <
typename Type,
size_t ArrayExtent>
228template <
typename Type,
size_t ArrayExtent>
231template <std::contiguous_iterator It,
typename End>
235template <
typename Type,
size_t Extent>
237inline rotated_span<
const std::byte, Extent == std::dynamic_extent
238 ? std::dynamic_extent
239 : Extent *
sizeof(Type)>
241 return {std::as_bytes(sp.
data()), sp.
offset() *
sizeof(Type)};
244template <
typename Type,
size_t Extent>
245 requires(!std::is_const_v<Type>)
247inline rotated_span<std::byte, Extent == std::dynamic_extent
248 ? std::dynamic_extent
249 : Extent * sizeof(Type)>
Definition rotated_span.h:147
constexpr reference operator*()
Definition rotated_span.h:168
rotated_span::value_type value_type
Definition rotated_span.h:150
rotated_span::pointer pointer
Definition rotated_span.h:152
rotated_span::reference reference
Definition rotated_span.h:153
constexpr bool operator==(const iterator &) const =default
std::forward_iterator_tag iterator_category
Definition rotated_span.h:149
rotated_span::difference_type difference_type
Definition rotated_span.h:151
constexpr iterator operator++(int) noexcept
Definition rotated_span.h:162
constexpr iterator(const rotated_span *obj, size_type idx) noexcept
Definition rotated_span.h:155
constexpr iterator & operator++() noexcept
Definition rotated_span.h:158
This is a simple rotated span view.
Definition rotated_span.h:37
constexpr size_type size_bytes() const noexcept
Definition rotated_span.h:122
constexpr std::span< T, Extent > data() const noexcept
Definition rotated_span.h:116
constexpr size_type count
Definition rotated_span.h:63
constexpr iterator end() const noexcept
Definition rotated_span.h:183
constexpr size_type size() const noexcept
Definition rotated_span.h:120
element_type & reference
Definition rotated_span.h:45
constexpr size_type int std::sized_sentinel_for< It > End constexpr End last
Definition rotated_span.h:69
constexpr iterator begin() const noexcept
Definition rotated_span.h:178
constexpr size_type offset() const noexcept
Definition rotated_span.h:118
constexpr reverse_iterator rend() const noexcept
Definition rotated_span.h:193
std::reverse_iterator< iterator > reverse_iterator
Definition rotated_span.h:175
constexpr reverse_iterator rbegin() const noexcept
Definition rotated_span.h:188
constexpr bool empty() const noexcept
Definition rotated_span.h:126
constexpr reference front() const noexcept
Definition rotated_span.h:131
T * pointer
Definition rotated_span.h:43
constexpr size_type int std::sized_sentinel_for< It > End constexpr End int size_t ArrayExtent constexpr rotated_span(std::array< Tp, ArrayExtent > &arr, int rotation=0) noexcept
Definition rotated_span.h:82
size_t size_type
Definition rotated_span.h:41
constexpr OExtent int rotation m_offset
Definition rotated_span.h:99
std::remove_cv_t< T > value_type
Definition rotated_span.h:40
constexpr rotated_span(const std::array< Tp, ArrayExtent > &arr, int rotation=0) noexcept
Definition rotated_span.h:87
constexpr rotated_span() noexcept=default
constexpr reference operator[](size_type idx) const noexcept
Definition rotated_span.h:141
constexpr OExtent int rotation noexcept
Definition rotated_span.h:98
T element_type
Definition rotated_span.h:39
constexpr size_type int rotation
Definition rotated_span.h:63
std::ptrdiff_t difference_type
Definition rotated_span.h:42
static constexpr size_t extent
Definition rotated_span.h:49
constexpr rotated_span rotate(int amt) const noexcept
Definition rotated_span.h:199
const T * const_pointer
Definition rotated_span.h:44
constexpr rotated_span(rotated_span &&) noexcept=default
constexpr reference back() const noexcept
Definition rotated_span.h:136
const element_type & const_reference
Definition rotated_span.h:46
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
Foonathan namespace.
Definition ntcore_cpp.h:26
rotated_span(Type(&)[ArrayExtent]) -> rotated_span< Type, ArrayExtent >
rotated_span< const std::byte, Extent==std::dynamic_extent ? std::dynamic_extent :Extent *sizeof(Type)> as_bytes(rotated_span< Type, Extent > sp) noexcept
Definition rotated_span.h:240
rotated_span< std::byte, Extent==std::dynamic_extent ? std::dynamic_extent :Extent *sizeof(Type)> as_writable_bytes(rotated_span< Type, Extent > sp) noexcept
Definition rotated_span.h:250