thrust

◆ is_sorted_until() [1/4]

template<typename DerivedPolicy , typename ForwardIterator >
__host__ __device__ ForwardIterator thrust::is_sorted_until ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last 
)

This version of is_sorted_until returns the last iterator i in [first,last] for which the range [first,last) is sorted using operator<. If distance(first,last) < 2, is_sorted_until simply returns last.

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

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the range of interest.
lastThe end of the range of interest.
Returns
The last iterator in the input range for which it is sorted.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator and ForwardIterator's value_type is a model of LessThan Comparable.

The following code snippet demonstrates how to use is_sorted_until to find the first position in an array where the data becomes unsorted using the thrust::host execution policy for parallelization:

#include <thrust/sort.h>
...
int A[8] = {0, 1, 2, 3, 0, 1, 2, 3};
// B - A is 4
// [A, B) is sorted
See also
is_sorted
sort
sort_by_key
stable_sort
stable_sort_by_key