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.

lower_bound.hpp 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_LOWER_BOUND_HPP
  15. #define RANGES_V3_ALGORITHM_LOWER_BOUND_HPP
  16. #include <range/v3/range_fwd.hpp>
  17. #include <range/v3/algorithm/aux_/lower_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/operations.hpp>
  22. #include <range/v3/iterator/traits.hpp>
  23. #include <range/v3/range/access.hpp>
  24. #include <range/v3/range/concepts.hpp>
  25. #include <range/v3/range/dangling.hpp>
  26. #include <range/v3/range/traits.hpp>
  27. #include <range/v3/utility/static_const.hpp>
  28. namespace ranges
  29. {
  30. /// \addtogroup group-algorithms
  31. /// @{
  32. RANGES_BEGIN_NIEBLOID(lower_bound)
  33. /// \brief function template \c lower_bound
  34. template<typename I,
  35. typename S,
  36. typename V,
  37. typename C = less,
  38. typename P = identity>
  39. auto RANGES_FUN_NIEBLOID(lower_bound)(
  40. I first, S last, V const & val, C pred = C{}, P proj = P{})
  41. ->CPP_ret(I)( //
  42. requires forward_iterator<I> && sentinel_for<S, I> &&
  43. indirect_strict_weak_order<C, V const *, projected<I, P>>)
  44. {
  45. return partition_point(std::move(first),
  46. std::move(last),
  47. detail::make_lower_bound_predicate(pred, val),
  48. std::move(proj));
  49. }
  50. /// \overload
  51. template<typename Rng, typename V, typename C = less, typename P = identity>
  52. auto RANGES_FUN_NIEBLOID(lower_bound)(
  53. Rng && rng, V const & val, C pred = C{}, P proj = P{})
  54. ->CPP_ret(safe_iterator_t<Rng>)( //
  55. requires forward_range<Rng> &&
  56. indirect_strict_weak_order<C, V const *, projected<iterator_t<Rng>, P>>)
  57. {
  58. return partition_point(
  59. rng, detail::make_lower_bound_predicate(pred, val), std::move(proj));
  60. }
  61. RANGES_END_NIEBLOID(lower_bound)
  62. namespace cpp20
  63. {
  64. using ranges::lower_bound;
  65. }
  66. /// @}
  67. } // namespace ranges
  68. #endif // include guard