24 Algorithms library [algorithms]

24.7 Sorting and related operations [alg.sorting]

24.7.3 Binary search [alg.binary.search]

24.7.3.3 equal_­range [equal.range]

template<class ForwardIterator, class T> constexpr pair<ForwardIterator, ForwardIterator> equal_range(ForwardIterator first, ForwardIterator last, const T& value); template<class ForwardIterator, class T, class Compare> constexpr pair<ForwardIterator, ForwardIterator> equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); namespace ranges { template<ForwardIterator I, Sentinel<I> S, class T, class Proj = identity, IndirectStrictWeakOrder<const T*, projected<I, Proj>> Comp = ranges::less<>> constexpr subrange<I> equal_range(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); template<ForwardRange R, class T, class Proj = identity, IndirectStrictWeakOrder<const T*, projected<iterator_t<R>, Proj>> Comp = ranges::less<>> constexpr safe_subrange_t<R> equal_range(R&& r, const T& value, Comp comp = {}, Proj proj = {}); }
Let comp be less{} and proj be identity{} for overloads with no parameters by those names.
Requires: The elements e of [first, last) shall be partitioned with respect to the expressions bool(invoke(comp, invoke(proj, e), value)) and !bool(invoke(comp, value, invoke(proj, e))).
Also, for all elements e of [first, last), bool(comp(e, value)) shall imply !bool(comp(​value, e)) for the overloads in namespace std.
Returns:
  • For the overloads in namespace std:
    \{lower_bound(first, last, value, comp),
     upper_bound(first, last, value, comp)\}
    
  • For the overloads in namespace ranges: {ranges::lower_bound(first, last, value, comp, proj), ranges::upper_bound(first, last, value, comp, proj)}
Complexity: At most comparisons and projections.