thrust

◆ is_partitioned() [1/2]

template<typename DerivedPolicy , typename InputIterator , typename Predicate >
__host__ __device__ bool thrust::is_partitioned ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
Predicate  pred 
)

is_partitioned returns true if the given range is partitioned with respect to a predicate, and false otherwise.

Specifically, is_partitioned returns true if [first, last) is empty of if [first, last) is partitioned by pred, i.e. if all elements that satisfy pred appear before those that do not.

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

Parameters
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.
Returns
true if the range [first, last) is partitioned with respect to pred, or if [first, last) is empty. false, otherwise.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratoris a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type.
Predicateis a model of Predicate.
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[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
thrust::is_partitioned(thrust::host, A, A + 10, is_even()); // returns true
thrust::is_partitioned(thrust::host, B, B + 10, is_even()); // returns false
See also
partition