Files
2025-10-25 03:02:53 +03:00

3.0 KiB

[upper.bound]

26 Algorithms library [algorithms]

26.8.4 Binary search [alg.binary.search]

26.8.4.3 upper_bound [upper.bound]

🔗

`template<class ForwardIterator, class T = iterator_traits::value_type> constexpr ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& value);

template<class ForwardIterator, class T = iterator_traits::value_type, class Compare> constexpr ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);

template<forward_iterator I, sentinel_for S, class Proj = identity, class T = projected_value_t<I, Proj>, indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less> constexpr I ranges::upper_bound(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); template<forward_range R, class Proj = identity, class T = projected_value_t<iterator_t, Proj>, indirect_strict_weak_order<const T*, projected<iterator_t, Proj>> Comp = ranges::less> constexpr borrowed_iterator_t ranges::upper_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {}); `

1

#

Let comp be less{} andproj be identity{} for overloads with no parameters by those names.

2

#

Preconditions: The elements e of [first, last) are partitioned with respect to the expression

!bool(invoke(comp, value, invoke(proj, e))).

3

#

Returns: The furthermost iterator i in the range [first, last] such that for every iterator j in the range [first, i),!bool(invoke(comp, value, invoke(proj, *j))) is true.

4

#

Complexity: At most log2(last - first)+O(1) comparisons and projections.