◆ partition_point() [1/2]

template<typename DerivedPolicy , typename ForwardIterator , typename Predicate >
__host__ __device__ ForwardIterator thrust::partition_point ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
Predicate  pred 

partition_point returns an iterator pointing to the end of the true partition of a partitioned range. partition_point requires the input range [first,last) to be a partition; that is, all elements which satisfy pred shall appear before those that do not.

The algorithm's execution is parallelized as determined by exec.

execThe execution policy to use for parallelization.
firstThe beginning of the range to consider.
lastThe end of the range to consider.
predA function object which decides to which partition each element of the range [first, last) belongs.
An iterator mid such that all_of(first, mid, pred) and none_of(mid, last, pred) are both true.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is convertible to Predicate's argument_type.
Predicateis a model of Predicate.
The range [first, last) shall be partitioned by pred.
Though similar, partition_point is not redundant with find_if_not. partition_point's precondition provides an opportunity for a faster implemention.
struct is_even
__host__ __device__
bool operator()(const int &x)
return (x % 2) == 0;
int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9};
int * B = thrust::partition_point(thrust::host, A, A + 10, is_even());
// B - A is 5
// [A, B) contains only even values
See also