Iros
Loading...
Searching...
No Matches
sort_heap.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
di/container/algorithm/pop_heap.h
"
4
#include "
di/container/concepts/prelude.h
"
5
#include "
di/container/iterator/distance.h
"
6
#include "
di/container/iterator/next.h
"
7
#include "
di/container/meta/prelude.h
"
8
#include "
di/function/compare.h
"
9
10
namespace
di::container
{
11
namespace
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
32
->
meta::BorrowedIterator<Con>
{
33
return
(*
this
)(
container::begin
(
container
),
container::end
(
container
),
util::ref
(comp),
util::ref
(
proj
));
34
}
35
};
36
}
37
38
constexpr
inline
auto
sort_heap
=
detail::SortHeapFunction
{};
39
}
40
41
namespace
di
{
42
using
container::sort_heap
;
43
}
di::concepts::Sortable
Definition
sortable.h:11
distance.h
compare.h
prelude.h
prelude.h
di::container::detail
Definition
sequence.h:13
di::container
Definition
sequence.h:12
di::container::end
constexpr auto end
Definition
end.h:47
di::container::pop_heap
constexpr auto pop_heap
Definition
pop_heap.h:83
di::container::sort_heap
constexpr auto sort_heap
Definition
sort_heap.h:38
di::container::begin
constexpr auto begin
Definition
begin.h:44
di::meta::BorrowedIterator
Conditional< concepts::BorrowedContainer< Con >, ContainerIterator< Con >, container::Dangling > BorrowedIterator
Definition
borrowed_iterator.h:11
di::util::ref
constexpr auto ref
Definition
reference_wrapper.h:98
di
Definition
zstring_parser.h:9
di::proj
constexpr auto proj
Definition
proj.h:59
next.h
pop_heap.h
di::container::detail::SortHeapFunction
Definition
sort_heap.h:12
libs
di
include
di
container
algorithm
sort_heap.h
Generated by
1.13.0