GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::partition_point(3) C++ Standard Libary std::partition_point(3)

std::partition_point - std::partition_point


Defined in header <algorithm>
template< class ForwardIt, class UnaryPredicate > (since C++11)
ForwardIt partition_point( ForwardIt first, ForwardIt last, (until C++20)
UnaryPredicate p );
template< class ForwardIt, class UnaryPredicate >
constexpr ForwardIt partition_point( ForwardIt first, ForwardIt last, (since C++20)
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.


first, last - the partitioned range of elements to examine
unary predicate which returns true for the elements found in the
beginning of the range.


The expression p(v) must be convertible to bool for every argument v
p - 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
, nor is VT unless for VT a move is equivalent to a copy
(since C++11).


-
ForwardIt must meet the requirements of LegacyForwardIterator.
-
UnaryPredicate must meet the requirements of Predicate.


The iterator past the end of the first partition within [first, last) or last if all
elements satisfy p.


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).


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; });.

// Run this code


#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>


auto print_seq = [](auto rem, auto first, auto last) {
for (std::cout << rem; first != last; std::cout << *first++ << ' ') {}
std::cout << '\n';
};


int main()
{
std::array v = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };


auto is_even = [](int i){ return i % 2 == 0; };


std::partition(v.begin(), v.end(), is_even);
print_seq("After partitioning, v: ", v.cbegin(), v.cend());


const auto pp = std::partition_point(v.cbegin(), v.cend(), is_even);
const auto i = std::distance(v.cbegin(), pp);
std::cout << "Partition point is at " << i << "; v[" << i << "] = " << *pp << '\n';


print_seq("First partition (all even elements): ", v.cbegin(), pp);
print_seq("Second partition (all odd elements): ", pp, v.cend());
}


After partitioning, v: 8 2 6 4 5 3 7 1 9
Partition point is at 4; v[4] = 5
First partition (all even elements): 8 2 6 4
Second partition (all odd elements): 5 3 7 1 9


find
find_if finds the first element satisfying specific criteria
find_if_not (function template)
(C++11)
is_sorted checks whether a range is sorted into ascending order
(C++11) (function template)
returns an iterator to the first element not less than the
lower_bound given value
(function template)
ranges::partition_point locates the partition point of a partitioned range
(C++20) (niebloid)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.