Skip to content

Commit 161d81c

Browse files
committed
Address review comments about lower_bound.h
1 parent 4f05ded commit 161d81c

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

libcxx/include/__algorithm/lower_bound.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,14 @@ _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lo
5757
// would yield \Omega(n*log(n)) comparisons and, for non-random iterators, \Omega(n^2) iterator increments, whereas the
5858
// one-sided version will yield O(n) operations on both counts, with a \Omega(log(n)) bound on the number of
5959
// comparisons.
60-
template <class _AlgPolicy, class _Iter, class _Sent, class _Type, class _Proj, class _Comp>
61-
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
62-
__lower_bound_onesided(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
63-
// static_assert(std::is_base_of<std::forward_iterator_tag, typename _IterOps<_AlgPolicy>::template
64-
// __iterator_category<_Iter>>::value,
65-
// "lower_bound() is a multipass algorithm and requires forward iterator or better");
66-
60+
template <class _AlgPolicy, class _ForwardIterator, class _Sent, class _Type, class _Proj, class _Comp>
61+
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
62+
__lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
6763
// step = 0, ensuring we can always short-circuit when distance is 1 later on
6864
if (__first == __last || !std::__invoke(__comp, std::__invoke(__proj, *__first), __value))
6965
return __first;
7066

71-
using _Distance = typename iterator_traits<_Iter>::difference_type;
67+
using _Distance = typename iterator_traits<_ForwardIterator>::difference_type;
7268
for (_Distance __step = 1; __first != __last; __step <<= 1) {
7369
auto __it = __first;
7470
auto __dist = __step - _IterOps<_AlgPolicy>::__advance_to(__it, __step, __last);
@@ -87,9 +83,9 @@ __lower_bound_onesided(_Iter __first, _Sent __last, const _Type& __value, _Comp&
8783
return __first;
8884
}
8985

90-
template <class _AlgPolicy, class _RandIter, class _Sent, class _Type, class _Proj, class _Comp>
91-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandIter
92-
__lower_bound(_RandIter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
86+
template <class _AlgPolicy, class _RandomAccessIterator, class _Sent, class _Type, class _Proj, class _Comp>
87+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
88+
__lower_bound(_RandomAccessIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
9389
const auto __dist = _IterOps<_AlgPolicy>::distance(__first, __last);
9490
return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj);
9591
}

0 commit comments

Comments
 (0)