Iros
 
Loading...
Searching...
No Matches
stable_partition.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace di::container {
8namespace detail {
10 template<concepts::InputIterator It, concepts::SentinelFor<It> Sent, typename Proj = function::Identity,
11 concepts::IndirectUnaryPredicate<meta::Projected<It, Proj>> Pred>
13 constexpr auto operator()(It first, Sent last, Pred pred, Proj proj = {}) const -> View<It> {
14 // Find the first element that does not belong to the left of the partition point.
15 auto pivot = container::find_if_not(util::move(first), last, util::ref(pred), util::ref(proj));
16 if (pivot == last) {
17 return { pivot, pivot };
18 }
19
20 // Swap any element which is out of place back into place.
21 // To preserve the relative order of elements, identity an
22 // entire chunk of misplaced elements using find_if and find_if_not.
23 // Then, rotate this entire block into place.
24 // TODO: try to allocate a temporary buffer to speed up the
25 // operation.
26 auto it = pivot;
27 while (it != last) {
28 it = container::find_if(util::move(it), last, util::ref(pred), util::ref(proj));
29 if (it == last) {
30 break;
31 }
32 auto next = container::find_if_not(it, last, util::ref(pred), util::ref(proj));
33 pivot = container::rotate(util::move(pivot), util::move(it), next).begin();
34 it = next;
35 }
36 return { util::move(pivot), util::move(it) };
37 }
38
39 template<concepts::InputContainer Con, typename Proj = function::Identity,
40 concepts::IndirectUnaryPredicate<meta::Projected<meta::ContainerIterator<Con>, Proj>> Pred>
41 requires(concepts::Permutable<meta::ContainerIterator<Con>>)
42 constexpr auto operator()(Con&& container, Pred pred, Proj proj = {}) const -> meta::BorrowedView<Con> {
44 }
45 };
46}
47
49}
50
51namespace di {
53}
Definition view.h:35
Definition permutable.h:9
Definition sequence.h:13
Definition sequence.h:12
constexpr auto next
Definition next.h:35
constexpr auto stable_partition
Definition stable_partition.h:48
constexpr auto find_if
Definition find_if.h:31
constexpr auto find_if_not
Definition find_if_not.h:31
constexpr auto end
Definition end.h:47
constexpr auto rotate
Definition rotate.h:94
constexpr auto begin
Definition begin.h:44
Conditional< concepts::BorrowedContainer< Con >, container::View< ContainerIterator< Con > >, container::Dangling > BorrowedView
Definition borrowed_view.h:12
constexpr auto ref
Definition reference_wrapper.h:98
Definition zstring_parser.h:9
constexpr auto proj
Definition proj.h:59
Definition stable_partition.h:9