11 Algorithms library [algorithms]

11.5 Sorting and related operations [alg.sorting]

11.5.3 Binary search [alg.binary.search]

11.5.3.2 upper_bound [upper.bound]

template <ForwardIterator I, Sentinel<I> S, class T, class Proj = identity, IndirectStrictWeakOrder<const T*, projected<I, Proj>> Comp = less<>> I upper_bound(I first, S last, const T& value, Comp comp = Comp{}, Proj proj = Proj{}); template <ForwardRange Rng, class T, class Proj = identity, IndirectStrictWeakOrder<const T*, projected<iterator_t<Rng>, Proj>> Comp = less<>> safe_iterator_t<Rng> upper_bound(Rng&& rng, const T& value, Comp comp = Comp{}, Proj proj = Proj{});

Requires: The elements e of [first,last) shall be partitioned with respect to the expression !invoke(comp, value, invoke(proj, e)).

Returns: The furthermost iterator i in the range [first,last] such that for every iterator j in the range [first,i) the following corresponding condition holds: invoke(comp, value, invoke(proj, *j)) == false.

Complexity: At most log2(last - first) + Ο(1) applications of the comparison function and projection.