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.

75 lines
2.5KB

  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2014-present
  5. // Copyright Casey Carter 2016
  6. //
  7. // Use, modification and distribution is subject to the
  8. // Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. //
  12. // Project home: https://github.com/ericniebler/range-v3
  13. //
  14. #ifndef RANGES_V3_ALGORITHM_UPPER_BOUND_HPP
  15. #define RANGES_V3_ALGORITHM_UPPER_BOUND_HPP
  16. #include <range/v3/range_fwd.hpp>
  17. #include <range/v3/algorithm/aux_/upper_bound_n.hpp>
  18. #include <range/v3/algorithm/partition_point.hpp>
  19. #include <range/v3/functional/comparisons.hpp>
  20. #include <range/v3/functional/identity.hpp>
  21. #include <range/v3/iterator/traits.hpp>
  22. #include <range/v3/range/concepts.hpp>
  23. #include <range/v3/range/dangling.hpp>
  24. #include <range/v3/range/traits.hpp>
  25. #include <range/v3/utility/static_const.hpp>
  26. namespace ranges
  27. {
  28. /// \addtogroup group-algorithms
  29. /// @{
  30. RANGES_BEGIN_NIEBLOID(upper_bound)
  31. /// \brief function template \c upper_bound
  32. template<typename I,
  33. typename S,
  34. typename V,
  35. typename C = less,
  36. typename P = identity>
  37. auto RANGES_FUN_NIEBLOID(upper_bound)(
  38. I first, S last, V const & val, C pred = C{}, P proj = P{}) //
  39. ->CPP_ret(I)( //
  40. requires forward_iterator<I> && sentinel_for<S, I> &&
  41. indirect_strict_weak_order<C, V const *, projected<I, P>>)
  42. {
  43. return partition_point(std::move(first),
  44. std::move(last),
  45. detail::make_upper_bound_predicate(pred, val),
  46. std::move(proj));
  47. }
  48. /// \overload
  49. template<typename Rng, typename V, typename C = less, typename P = identity>
  50. auto RANGES_FUN_NIEBLOID(upper_bound)(
  51. Rng && rng, V const & val, C pred = C{}, P proj = P{}) //
  52. ->CPP_ret(safe_iterator_t<Rng>)( //
  53. requires forward_range<Rng> &&
  54. indirect_strict_weak_order<C, V const *, projected<iterator_t<Rng>, P>>)
  55. {
  56. return partition_point(
  57. rng, detail::make_upper_bound_predicate(pred, val), std::move(proj));
  58. }
  59. RANGES_END_NIEBLOID(upper_bound)
  60. namespace cpp20
  61. {
  62. using ranges::upper_bound;
  63. }
  64. /// @}
  65. } // namespace ranges
  66. #endif // include guard