di 0.1.0
Loading...
Searching...
No Matches
shift_left.h
Go to the documentation of this file.
1#pragma once
2
8#include "di/util/move.h"
9
10namespace di::container {
11namespace detail {
12 struct ShiftLeftFunction {
13 template<concepts::Permutable It, concepts::SentinelFor<It> Sent>
14 constexpr auto operator()(It first, Sent last, meta::IteratorSSizeType<It> n) const -> View<It> {
15 DI_ASSERT(n >= 0);
16
17 if (n == 0) {
18 return { first, container::next(first, last) };
19 }
20
21 auto new_start = first;
22 container::advance(new_start, n, last);
23
24 if (new_start == last) {
25 return { first, first };
26 }
27
28 auto result = container::move(util::move(new_start), last, first);
29 return { first, result.out };
30 }
31
32 template<concepts::ForwardContainer Con>
33 requires(concepts::Permutable<meta::ContainerIterator<Con>>)
34 constexpr auto operator()(Con&& container, meta::ContainerSSizeType<Con> n) const -> meta::BorrowedView<Con> {
35 return (*this)(container::begin(container), container::end(container), n);
36 }
37 };
38}
39
40constexpr inline auto shift_left = detail::ShiftLeftFunction {};
41}
42
43namespace di {
45}
#define DI_ASSERT(...)
Definition assert_bool.h:7
constexpr auto first(concepts::detail::ConstantVector auto &vector, size_t count)
Definition vector_first.h:13
Definition sequence.h:12
constexpr auto next
Definition next.h:35
constexpr auto move
Definition move.h:38
constexpr auto shift_left
Definition shift_left.h:40
View(Iter, Sent) -> View< Iter, Sent >
constexpr auto end
Definition end.h:55
constexpr auto advance
Definition advance.h:62
constexpr auto begin
Definition begin.h:52
IteratorSSizeType< ContainerIterator< T > > ContainerSSizeType
Definition container_ssize_type.h:8
decltype(container::iterator_ssize_type(types::in_place_type< meta::RemoveCVRef< T > >)) IteratorSSizeType
Definition iterator_ssize_type.h:8
Conditional< concepts::BorrowedContainer< Con >, container::View< ContainerIterator< Con > >, container::Dangling > BorrowedView
Definition borrowed_view.h:12
Definition any_storable.h:9