Template Struct negate¶
Defined in File functional.h
Struct Documentation¶
-
template<typename
T
>
structnegate
¶ negate
is a function object. Specifically, it is an Adaptable Unary Function. Iff
is an object of classnegate<T>
, andx
is an object of classT
, thenf(x)
returns-x
.The following code snippet demonstrates how to use
negate
to negate the element of a device_vector offloats
.- Template Parameters
T
: is a model of Assignable, and ifx
is an object of typeT
, then-x
must be defined and must have a return type that is convertible toT
.
#include <thrust/device_vector.h> #include <thrust/functional.h> #include <thrust/sequence.h> #include <thrust/transform.h> ... const int N = 1000; thrust::device_vector<float> V1(N); thrust::device_vector<float> V2(N); thrust::sequence(V1.begin(), V1.end(), 1); thrust::transform(V1.begin(), V1.end(), V2.begin(), thrust::negate<float>()); // V2 is now {-1, -2, -3, ..., -1000}
Public Types
-
typedef
argument_type
¶ The type of the function object’s argument.
-
typedef
result_type
¶ The type of the function object’s result;.
Public Functions
-
__host__ __device__ T thrust::negate::operator()(const T & x) const
Function call operator. The return value is
-x
.