di 0.1.0
Loading...
Searching...
No Matches
max_element.h
Go to the documentation of this file.
1#pragma once
2
7#include "di/util/move.h"
9
10namespace di::container {
11namespace detail {
12 struct MaxElementFunction {
13 template<concepts::ForwardIterator It, concepts::SentinelFor<It> Sent, typename Proj = function::Identity,
14 concepts::IndirectStrictWeakOrder<meta::Projected<It, Proj>> Comp = function::Compare>
15 constexpr auto operator()(It first, Sent last, Comp comp = {}, Proj proj = {}) const -> It {
16 if (first == last) {
17 return first;
18 }
19
20 auto min_iter = first;
21 for (auto it = ++first; it != last; ++it) {
22 if (function::invoke(comp, function::invoke(proj, *it), function::invoke(proj, *min_iter)) > 0) {
23 min_iter = it;
24 }
25 }
26 return min_iter;
27 }
28
29 template<concepts::ForwardContainer Con, typename Proj = function::Identity,
30 concepts::IndirectStrictWeakOrder<meta::Projected<meta::ContainerIterator<Con>, Proj>> Comp =
31 function::Compare>
32 constexpr auto operator()(Con&& container, Comp comp = {}, Proj proj = {}) const
34 return (*this)(container::begin(container), container::end(container), util::ref(comp), util::ref(proj));
35 }
36 };
37}
38
39constexpr inline auto max_element = detail::MaxElementFunction {};
40}
41
42namespace di {
44}
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 max_element
Definition max_element.h:39
constexpr auto end
Definition end.h:55
constexpr auto begin
Definition begin.h:52
constexpr auto invoke
Definition invoke.h:100
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