thrust

◆ THRUST_PREVENT_MACRO_SUBSTITUTION() [1/4]

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

This version of min returns the smaller of two values, given a comparison operation.

Parameters
lhsThe first value to compare.
rhsThe second value to compare.
compA comparison operation.
Returns
The smaller 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 min to compute the smaller 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 smaller = thrust::min(a, b, compare_key_value());
// smaller is {7, 1}
Note
Returns the first argument when the arguments are equivalent.
See also
max

Referenced by thrust::device_new_allocator< T >::max_size().