File indexing completed on 2026-05-03 08:13:10
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H
0010 #define _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H
0011
0012 #include <__algorithm/half_positive.h>
0013 #include <__config>
0014 #include <__functional/identity.h>
0015 #include <__functional/invoke.h>
0016 #include <__iterator/concepts.h>
0017 #include <__iterator/distance.h>
0018 #include <__iterator/iterator_traits.h>
0019 #include <__iterator/next.h>
0020 #include <__iterator/projected.h>
0021 #include <__ranges/access.h>
0022 #include <__ranges/concepts.h>
0023 #include <__ranges/dangling.h>
0024 #include <__utility/move.h>
0025
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 # pragma GCC system_header
0028 #endif
0029
0030 _LIBCPP_PUSH_MACROS
0031 #include <__undef_macros>
0032
0033 #if _LIBCPP_STD_VER >= 20
0034
0035 _LIBCPP_BEGIN_NAMESPACE_STD
0036
0037 namespace ranges {
0038 struct __partition_point {
0039
0040 template <class _Iter, class _Sent, class _Proj, class _Pred>
0041 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
0042 __partition_point_fn_impl(_Iter&& __first, _Sent&& __last, _Pred& __pred, _Proj& __proj) {
0043 auto __len = ranges::distance(__first, __last);
0044
0045 while (__len != 0) {
0046 auto __half_len = std::__half_positive(__len);
0047 auto __mid = ranges::next(__first, __half_len);
0048
0049 if (std::invoke(__pred, std::invoke(__proj, *__mid))) {
0050 __first = ++__mid;
0051 __len -= __half_len + 1;
0052
0053 } else {
0054 __len = __half_len;
0055 }
0056 }
0057
0058 return __first;
0059 }
0060
0061 template <forward_iterator _Iter,
0062 sentinel_for<_Iter> _Sent,
0063 class _Proj = identity,
0064 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
0065 _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
0066 return __partition_point_fn_impl(std::move(__first), std::move(__last), __pred, __proj);
0067 }
0068
0069 template <forward_range _Range,
0070 class _Proj = identity,
0071 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
0072 _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range>
0073 operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
0074 return __partition_point_fn_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
0075 }
0076 };
0077
0078 inline namespace __cpo {
0079 inline constexpr auto partition_point = __partition_point{};
0080 }
0081 }
0082
0083 _LIBCPP_END_NAMESPACE_STD
0084
0085 #endif
0086
0087 _LIBCPP_POP_MACROS
0088
0089 #endif