File indexing completed on 2026-05-03 08:13:09
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
0010 #define _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
0011
0012 #include <__algorithm/iterator_operations.h>
0013 #include <__algorithm/lower_bound.h>
0014 #include <__config>
0015 #include <__functional/identity.h>
0016 #include <__functional/invoke.h>
0017 #include <__functional/ranges_operations.h>
0018 #include <__iterator/concepts.h>
0019 #include <__iterator/projected.h>
0020 #include <__ranges/access.h>
0021 #include <__ranges/concepts.h>
0022
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 # pragma GCC system_header
0025 #endif
0026
0027 _LIBCPP_PUSH_MACROS
0028 #include <__undef_macros>
0029
0030 #if _LIBCPP_STD_VER >= 20
0031
0032 _LIBCPP_BEGIN_NAMESPACE_STD
0033
0034 namespace ranges {
0035 struct __binary_search {
0036 template <forward_iterator _Iter,
0037 sentinel_for<_Iter> _Sent,
0038 class _Type,
0039 class _Proj = identity,
0040 indirect_strict_weak_order<const _Type*, projected<_Iter, _Proj>> _Comp = ranges::less>
0041 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool
0042 operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
0043 auto __ret = std::__lower_bound<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj);
0044 return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret));
0045 }
0046
0047 template <forward_range _Range,
0048 class _Type,
0049 class _Proj = identity,
0050 indirect_strict_weak_order<const _Type*, projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
0051 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool
0052 operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
0053 auto __first = ranges::begin(__r);
0054 auto __last = ranges::end(__r);
0055 auto __ret = std::__lower_bound<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj);
0056 return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret));
0057 }
0058 };
0059
0060 inline namespace __cpo {
0061 inline constexpr auto binary_search = __binary_search{};
0062 }
0063 }
0064
0065 _LIBCPP_END_NAMESPACE_STD
0066
0067 #endif
0068
0069 _LIBCPP_POP_MACROS
0070
0071 #endif