std::partition_point (3) - Linux Manuals
std::partition_point: std::partition_point
NAME
std::partition_point - std::partition_point
Synopsis
Defined in header <algorithm>
template< class ForwardIt, class UnaryPredicate > (since C++11)
ForwardIt partition_point( ForwardIt first, ForwardIt last, UnaryPredicate p ); (1) (until C++20)
template< class ForwardIt, class UnaryPredicate > (since C++20)
constexpr ForwardIt partition_point( ForwardIt first, ForwardIt last, UnaryPredicate p );
Examines the partitioned (as if by std::partition) range [first, last) and locates the end of the first partition, that is, the first element that does not satisfy p or last if all elements satisfy p.
Parameters
first, last - the partitioned range of elements to examine
p - The expression p(v) must be convertible to bool for every argument v of type (possibly const) VT, where VT is the value type of ForwardIt, regardless of value_category, and must not modify v. Thus, a parameter type of VT&is not allowed
Type requirements
-
ForwardIt must meet the requirements of LegacyForwardIterator.
-
UnaryPredicate must meet the requirements of Predicate.
Return value
The iterator past the end of the first partition within [first, last) or last if all elements satisfy p.
Complexity
Given N = std::distance(first, last), performs O(log N) applications of the predicate p.
However, for non-LegacyRandomAccessIterators, the number of iterator increments is O(N).
Notes
This algorithm is a more general form of std::lower_bound, which can be expressed in terms of std::partition_point with the predicate [&](auto const& e) { return e < value; });.
Example
// Run this code
Output:
See also
is_sorted checks whether a range is sorted into ascending order
(C++11)
lower_bound (function template)