File indexing completed on 2026-05-03 08:13:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_EQUAL_RANGE_H
0010 #define _LIBCPP___CXX03___ALGORITHM_EQUAL_RANGE_H
0011
0012 #include <__cxx03/__algorithm/comp.h>
0013 #include <__cxx03/__algorithm/comp_ref_type.h>
0014 #include <__cxx03/__algorithm/half_positive.h>
0015 #include <__cxx03/__algorithm/iterator_operations.h>
0016 #include <__cxx03/__algorithm/lower_bound.h>
0017 #include <__cxx03/__algorithm/upper_bound.h>
0018 #include <__cxx03/__config>
0019 #include <__cxx03/__functional/identity.h>
0020 #include <__cxx03/__functional/invoke.h>
0021 #include <__cxx03/__iterator/advance.h>
0022 #include <__cxx03/__iterator/distance.h>
0023 #include <__cxx03/__iterator/iterator_traits.h>
0024 #include <__cxx03/__iterator/next.h>
0025 #include <__cxx03/__type_traits/is_callable.h>
0026 #include <__cxx03/__type_traits/is_constructible.h>
0027 #include <__cxx03/__utility/move.h>
0028 #include <__cxx03/__utility/pair.h>
0029
0030 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0031 # pragma GCC system_header
0032 #endif
0033
0034 _LIBCPP_PUSH_MACROS
0035 #include <__cxx03/__undef_macros>
0036
0037 _LIBCPP_BEGIN_NAMESPACE_STD
0038
0039 template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj>
0040 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter>
0041 __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) {
0042 auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
0043 _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last);
0044 while (__len != 0) {
0045 auto __half_len = std::__half_positive(__len);
0046 _Iter __mid = _IterOps<_AlgPolicy>::next(__first, __half_len);
0047 if (std::__invoke(__comp, std::__invoke(__proj, *__mid), __value)) {
0048 __first = ++__mid;
0049 __len -= __half_len + 1;
0050 } else if (std::__invoke(__comp, __value, std::__invoke(__proj, *__mid))) {
0051 __end = __mid;
0052 __len = __half_len;
0053 } else {
0054 _Iter __mp1 = __mid;
0055 return pair<_Iter, _Iter>(std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
0056 std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
0057 }
0058 }
0059 return pair<_Iter, _Iter>(__first, __first);
0060 }
0061
0062 template <class _ForwardIterator, class _Tp, class _Compare>
0063 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
0064 equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
0065 static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
0066 static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible");
0067 return std::__equal_range<_ClassicAlgPolicy>(
0068 std::move(__first),
0069 std::move(__last),
0070 __value,
0071 static_cast<__comp_ref_type<_Compare> >(__comp),
0072 std::__identity());
0073 }
0074
0075 template <class _ForwardIterator, class _Tp>
0076 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
0077 equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
0078 return std::equal_range(std::move(__first), std::move(__last), __value, __less<>());
0079 }
0080
0081 _LIBCPP_END_NAMESPACE_STD
0082
0083 _LIBCPP_POP_MACROS
0084
0085 #endif