thrust::max

Defined in thrust/extrema.h

template<typename T, typename BinaryPredicate>
T thrust::max(const T &lhs, const T &rhs, BinaryPredicate comp)

This version of max

returns the larger of two values, given a comparison operation.

The following code snippet demonstrates how to use

max to compute the larger of two key-value objects.

#include <thrust/extrema.h>
...
struct key_value
{
  int key;
  int value;
};

struct compare_key_value
{
  __host__ __device__
  bool operator()(key_value lhs, key_value rhs)
  {
    return lhs.key < rhs.key;
  }
};

...
key_value a = {13, 0};
key_value b = { 7, 1);

key_value larger = thrust::max(a, b, compare_key_value());

// larger is {13, 0}

See also

min

Note

Returns the first argument when the arguments are equivalent.

Parameters
  • lhs – The first value to compare.

  • rhs – The second value to compare.

  • comp – A comparison operation.

Template Parameters
  • T – is convertible to BinaryPredicate's first argument type and to its second argument type.

  • BinaryPredicate – is a model of BinaryPredicate.

Returns

The larger element.