is_sorted_until#

Overloads#

is_sorted_until(exec, first, last)#

template<typename DerivedPolicy, typename ForwardIterator>
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.

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>
#include <thrust/execution_policy.h>

...

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

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

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

See also

is_sorted

See also

sort

See also

sort_by_key

See also

stable_sort

Parameters:
  • exec – The execution policy to use for parallelization.

  • first – The beginning of the range of interest.

  • last – The end of the range of interest.

Template Parameters:
  • DerivedPolicy – The name of the derived execution policy.

  • ForwardIterator – is a model of Forward Iterator and ForwardIterator's value_type is a model of LessThan Comparable.

Returns:

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

is_sorted_until(first, last)#

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:

#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 also

is_sorted

See also

sort

See also

sort_by_key

See also

stable_sort

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

  • last – The end of the range of interest.

Template Parameters:

ForwardIterator – is a model of Forward Iterator and ForwardIterator's value_type is a model of LessThan Comparable.

Returns:

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

is_sorted_until(exec, first, last, comp)#

template<typename DerivedPolicy, typename ForwardIterator, typename Compare>
ForwardIterator thrust::is_sorted_until(
const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
ForwardIterator first,
ForwardIterator last,
Compare comp,
)#

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

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

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

#include <thrust/sort.h>
#include <thrust/functional.h>
#include <thrust/execution_policy.h>

...

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

::cuda::std::greater<int> comp;
int * B = thrust::is_sorted_until(thrust::host, A, A + 8, comp);

// B - A is 4
// [A, B) is sorted in descending order

See also

is_sorted

See also

sort

See also

sort_by_key

See also

stable_sort

Parameters:
  • exec – The execution policy to use for parallelization:

  • first – The beginning of the range of interest.

  • last – The end of the range of interest.

  • comp – The function object to use for comparison.

Template Parameters:
  • DerivedPolicy – The name of the derived execution policy.

  • ForwardIterator – is a model of Forward Iterator and ForwardIterator's value_type is convertible to Compare's argument type.

  • Compare – is a model of Strict Weak Ordering.

Returns:

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

is_sorted_until(first, last, comp)#

template<typename ForwardIterator, typename Compare>
ForwardIterator thrust::is_sorted_until(
ForwardIterator first,
ForwardIterator last,
Compare comp,
)#

This version of is_sorted_until returns the last iterator i in [first,last] for which the range [first,last) is sorted using the function object comp. 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 in descending order:

#include <thrust/sort.h>
#include <thrust/functional.h>

...

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

::cuda::std::greater<int> comp;
int * B = thrust::is_sorted_until(A, A + 8, comp);

// B - A is 4
// [A, B) is sorted in descending order

See also

is_sorted

See also

sort

See also

sort_by_key

See also

stable_sort

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

  • last – The end of the range of interest.

  • comp – The function object to use for comparison.

Template Parameters:
Returns:

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