Debian Codegraph @

3rd_party/range-v3/range/v3/algorithm/min_element.hpp

raw
1 /// \file
2 // Range v3 library
3 //
4 // Copyright Eric Niebler 2014-present
5 //
6 // Use, modification and distribution is subject to the
7 // Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // Project home: https://github.com/ericniebler/range-v3
12 //
13 #ifndef RANGES_V3_ALGORITHM_MIN_ELEMENT_HPP
14 #define RANGES_V3_ALGORITHM_MIN_ELEMENT_HPP
15
16 #include <range/v3/range_fwd.hpp>
17
18 #include <range/v3/functional/comparisons.hpp>
19 #include <range/v3/functional/identity.hpp>
20 #include <range/v3/functional/invoke.hpp>
21 #include <range/v3/iterator/concepts.hpp>
22 #include <range/v3/iterator/operations.hpp>
23 #include <range/v3/iterator/traits.hpp>
24 #include <range/v3/range/access.hpp>
25 #include <range/v3/range/concepts.hpp>
26 #include <range/v3/range/dangling.hpp>
27 #include <range/v3/range/traits.hpp>
28 #include <range/v3/utility/static_const.hpp>
29
30 #include <range/v3/detail/prologue.hpp>
31
32 namespace ranges
33 {
34 /// \addtogroup group-algorithms
35 /// @{
36 RANGES_FUNC_BEGIN(min_element)
37
38 /// \brief function template \c min_element
39 template(typename I, typename S, typename C = less, typename P = identity)(
40 requires forward_iterator<I> AND sentinel_for<S, I> AND
41 indirect_strict_weak_order<C, projected<I, P>>)
42 constexpr I RANGES_FUNC(min_element)(I first, S last, C pred = C{}, P proj = P{})
43 {
44 if(first != last)
45 for(auto tmp = next(first); tmp != last; ++tmp)
46 if(invoke(pred, invoke(proj, *tmp), invoke(proj, *first)))
47 first = tmp;
48 return first;
49 }
50
51 /// \overload
52 template(typename Rng, typename C = less, typename P = identity)(
53 requires forward_range<Rng> AND
54 indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>>)
55 constexpr borrowed_iterator_t<Rng> //
56 RANGES_FUNC(min_element)(Rng && rng, C pred = C{}, P proj = P{}) //
57 {
58 return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
59 }
60
61 RANGES_FUNC_END(min_element)
62
63 namespace cpp20
64 {
65 using ranges::min_element;
66 }
67 /// @}
68 } // namespace ranges
69
70 #include <range/v3/detail/epilogue.hpp>
71
72 #endif