di 0.1.0
Loading...
Searching...
No Matches
sort_heap.h
Go to the documentation of this file.
1#pragma once
2
9
10namespace di::container {
11namespace detail {
12 struct SortHeapFunction {
13 template<concepts::RandomAccessIterator It, concepts::SentinelFor<It> Sent, typename Comp = function::Compare,
14 typename Proj = function::Identity>
15 requires(concepts::Sortable<It, Comp, Proj>)
16 constexpr auto operator()(It first, Sent last, Comp comp = {}, Proj proj = {}) const -> It {
17 if (first == last) {
18 return first;
19 }
20
21 auto result = container::pop_heap(first, last, util::ref(comp), util::ref(proj));
22 for (--last; first != last; --last) {
23 container::pop_heap(first, last, util::ref(comp), util::ref(proj));
24 }
25 return result;
26 }
27
28 template<concepts::RandomAccessContainer Con, typename Comp = function::Compare,
29 typename Proj = function::Identity>
30 requires(concepts::Sortable<meta::ContainerIterator<Con>, Comp, Proj>)
31 constexpr auto operator()(Con&& container, Comp comp = {}, Proj proj = {}) const
33 return (*this)(container::begin(container), container::end(container), util::ref(comp), util::ref(proj));
34 }
35 };
36}
37
38constexpr inline auto sort_heap = detail::SortHeapFunction {};
39}
40
41namespace di {
43}
constexpr auto last(concepts::detail::ConstantVector auto &vector, size_t count)
Definition vector_last.h:13
constexpr auto first(concepts::detail::ConstantVector auto &vector, size_t count)
Definition vector_first.h:13
Definition sequence.h:12
constexpr auto end
Definition end.h:55
constexpr auto pop_heap
Definition pop_heap.h:83
constexpr auto sort_heap
Definition sort_heap.h:38
constexpr auto begin
Definition begin.h:52
Conditional< concepts::BorrowedContainer< Con >, ContainerIterator< Con >, container::Dangling > BorrowedIterator
Definition borrowed_iterator.h:11
constexpr auto ref
Definition reference_wrapper.h:98
Definition any_storable.h:9
constexpr auto proj
Definition proj.h:59