thrust

◆ THRUST_PREVENT_MACRO_SUBSTITUTION() [3/4]

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

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

Parameters
lhsThe first value to compare.
rhsThe second value to compare.
compA comparison operation.
Returns
The larger element.
Template Parameters
Tis convertible to BinaryPredicate's first argument type and to its second argument type.
BinaryPredicateis a model of BinaryPredicate.

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}
Note
Returns the first argument when the arguments are equivalent.
See also
min