File indexing completed on 2025-12-16 10:27:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #ifndef RANGES_V3_ALGORITHM_PARTITION_POINT_HPP
0023 #define RANGES_V3_ALGORITHM_PARTITION_POINT_HPP
0024
0025 #include <meta/meta.hpp>
0026
0027 #include <range/v3/range_fwd.hpp>
0028
0029 #include <range/v3/algorithm/aux_/partition_point_n.hpp>
0030 #include <range/v3/functional/identity.hpp>
0031 #include <range/v3/functional/invoke.hpp>
0032 #include <range/v3/iterator/concepts.hpp>
0033 #include <range/v3/iterator/operations.hpp>
0034 #include <range/v3/iterator/traits.hpp>
0035 #include <range/v3/range/access.hpp>
0036 #include <range/v3/range/concepts.hpp>
0037 #include <range/v3/range/dangling.hpp>
0038 #include <range/v3/range/traits.hpp>
0039 #include <range/v3/utility/static_const.hpp>
0040
0041 #include <range/v3/detail/prologue.hpp>
0042
0043 namespace ranges
0044 {
0045
0046
0047
0048 RANGES_FUNC_BEGIN(partition_point)
0049
0050
0051 template(typename I, typename S, typename C, typename P = identity)(
0052 requires forward_iterator<I> AND sentinel_for<S, I> AND
0053 indirect_unary_predicate<C, projected<I, P>>)
0054 constexpr I RANGES_FUNC(partition_point)(I first, S last, C pred, P proj = P{})
0055 {
0056 if(RANGES_CONSTEXPR_IF(sized_sentinel_for<S, I>))
0057 {
0058 auto len = distance(first, std::move(last));
0059 return aux::partition_point_n(
0060 std::move(first), len, std::move(pred), std::move(proj));
0061 }
0062
0063
0064
0065 auto len = iter_difference_t<I>{1};
0066 while(true)
0067 {
0068 auto mid = first;
0069 auto d = advance(mid, len, last);
0070 if(mid == last || !invoke(pred, invoke(proj, *mid)))
0071 {
0072 len -= d;
0073 return aux::partition_point_n(
0074 std::move(first), len, ranges::ref(pred), ranges::ref(proj));
0075 }
0076 first = std::move(mid);
0077 len *= 2;
0078 }
0079 }
0080
0081
0082 template(typename Rng, typename C, typename P = identity)(
0083 requires forward_range<Rng> AND
0084 indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
0085 constexpr borrowed_iterator_t<Rng>
0086 RANGES_FUNC(partition_point)(Rng && rng, C pred, P proj = P{})
0087 {
0088 if(RANGES_CONSTEXPR_IF(sized_range<Rng>))
0089 {
0090 auto len = distance(rng);
0091 return aux::partition_point_n(
0092 begin(rng), len, std::move(pred), std::move(proj));
0093 }
0094 return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
0095 }
0096
0097 RANGES_FUNC_END(partition_point)
0098
0099 namespace cpp20
0100 {
0101 using ranges::partition_point;
0102 }
0103
0104 }
0105
0106 #include <range/v3/detail/epilogue.hpp>
0107
0108 #endif