VCCC  2024.05
VisualCamp Common C++ library
min_element.hpp
Go to the documentation of this file.
1 //
2 // Created by YongGyu Lee on 01/08/24.
3 //
4 
5 #ifndef VCCC_ALGORITHM_RANGES_MIN_ELEMENT_HPP
6 #define VCCC_ALGORITHM_RANGES_MIN_ELEMENT_HPP
7 
14 #include "vccc/__ranges/begin.hpp"
16 #include "vccc/__ranges/end.hpp"
17 
18 namespace vccc {
19 namespace ranges {
20 namespace detail {
21 
22 struct min_element_niebloid {
23  template<typename I, typename S, typename Proj = identity, typename Comp = ranges::less, std::enable_if_t<
24  algo_check_unary_input_iterator<indirect_strict_weak_order, I, S, Proj, Comp>
25  ::value, int> = 0>
26  constexpr I operator()(I first, S last, Comp comp = {}, Proj proj = {}) const {
27  if (first == last)
28  return last;
29 
30  auto it = first;
31  for (++first; first != last; ++first) {
32  if (vccc::invoke(comp, vccc::invoke(proj, *first), vccc::invoke(proj, *it)))
33  it = first;
34  }
35  return it;
36  }
37 
38  template<typename R, typename Proj = identity, typename Comp = less, std::enable_if_t<
39  algo_check_unary_input_range<indirect_strict_weak_order, R, Proj, Comp>
40  ::value, int> = 0>
41  constexpr borrowed_iterator_t<R>
42  operator()(R&& r, Comp comp = {}, Proj proj = {}) const {
43  return (*this)(ranges::begin(r), ranges::end(r), comp, proj);
44  }
45 };
46 
47 } // namespace detail
48 
51 
52 VCCC_INLINE_OR_STATIC constexpr detail::min_element_niebloid min_element{};
53 
55 
56 } // namespace ranges
57 } // namespace vccc
58 
59 #endif // VCCC_ALGORITHM_RANGES_MIN_ELEMENT_HPP
constexpr VCCC_INLINE_OR_STATIC detail::min_element_niebloid min_element
Definition: min_element.hpp:52
constexpr invoke_result_t< F, Args... > invoke(F &&f, Args &&... args) noexcept(is_nothrow_invocable< F, Args... >::value)
Definition: invoke.hpp:38
constexpr VCCC_INLINE_OR_STATIC detail::begin_niebloid begin
returns an iterator to the beginning of a range
Definition: begin.hpp:116
constexpr VCCC_INLINE_OR_STATIC detail::end_niebloid end
returns a sentinel indicating the end of a range
Definition: end.hpp:120
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 0 > first
Definition: key_value.hpp:34
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35