You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 line
2.3KB

  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. #include <range/v3/range_fwd.hpp>
  16. #include <range/v3/functional/comparisons.hpp>
  17. #include <range/v3/functional/identity.hpp>
  18. #include <range/v3/functional/invoke.hpp>
  19. #include <range/v3/iterator/concepts.hpp>
  20. #include <range/v3/iterator/operations.hpp>
  21. #include <range/v3/iterator/traits.hpp>
  22. #include <range/v3/range/access.hpp>
  23. #include <range/v3/range/concepts.hpp>
  24. #include <range/v3/range/dangling.hpp>
  25. #include <range/v3/range/traits.hpp>
  26. #include <range/v3/utility/static_const.hpp>
  27. namespace ranges
  28. {
  29. /// \addtogroup group-algorithms
  30. /// @{
  31. RANGES_BEGIN_NIEBLOID(min_element)
  32. /// \brief function template \c min_element
  33. template<typename I, typename S, typename C = less, typename P = identity>
  34. auto RANGES_FUN_NIEBLOID(min_element)(
  35. I first, S last, C pred = C{}, P proj = P{}) //
  36. ->CPP_ret(I)( //
  37. requires forward_iterator<I> && sentinel_for<S, I> &&
  38. indirect_strict_weak_order<C, projected<I, P>>)
  39. {
  40. if(first != last)
  41. for(auto tmp = next(first); tmp != last; ++tmp)
  42. if(invoke(pred, invoke(proj, *tmp), invoke(proj, *first)))
  43. first = tmp;
  44. return first;
  45. }
  46. /// \overload
  47. template<typename Rng, typename C = less, typename P = identity>
  48. auto RANGES_FUN_NIEBLOID(min_element)(Rng && rng, C pred = C{}, P proj = P{}) //
  49. ->CPP_ret(safe_iterator_t<Rng>)( //
  50. requires forward_range<Rng> &&
  51. indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>>)
  52. {
  53. return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
  54. }
  55. RANGES_END_NIEBLOID(min_element)
  56. namespace cpp20
  57. {
  58. using ranges::min_element;
  59. }
  60. /// @}
  61. } // namespace ranges
  62. #endif // include guard