Template Function thrust::max_element(ForwardIterator, ForwardIterator)

Function Documentation

template<typename ForwardIterator>
ForwardIterator thrust::max_element(ForwardIterator first, ForwardIterator last)

max_element finds the largest element in the range [first, last). It returns the first iterator i in [first, last) such that no other iterator in [first, last) points to a value larger than *i. The return value is last if and only if [first, last) is an empty range.

The two versions of max_element differ in how they define whether one element is greater than another. This version compares objects using operator<. Specifically, this version of max_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), *i < *j is false.

#include <thrust/extrema.h>
...
int data[6] = {1, 0, 2, 2, 1, 3};
int *result = thrust::max_element(data, data + 6);

// *result == 3
Return

An iterator pointing to the largest element of the range [first, last), if it is not an empty range; last, otherwise.

Parameters
  • first: The beginning of the sequence.

  • last: The end of the sequence.

Template Parameters

See

http://www.sgi.com/tech/stl/max_element.html