Template Function thrust::is_sorted_until(ForwardIterator, ForwardIterator)

Function Documentation

template<typename ForwardIterator>
ForwardIterator thrust::is_sorted_until(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 following code snippet demonstrates how to use

is_sorted_until to find the first position in an array where the data becomes unsorted:
Return

The last iterator in the input range for which it is sorted.

Parameters
  • first: The beginning of the range of interest.

  • last: The end of the range of interest.

Template Parameters

#include <thrust/sort.h>

...
 
int A[8] = {0, 1, 2, 3, 0, 1, 2, 3};

int * B = thrust::is_sorted_until(A, A + 8);

// B - A is 4
// [A, B) is sorted

See

is_sorted

See

sort

See

sort_by_key

See

stable_sort

See

stable_sort_by_key