◆ transform() [1/4]

template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename UnaryFunction >
__host__ __device__ OutputIterator thrust::transform ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
OutputIterator  result,
UnaryFunction  op 

This version of transform applies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence. Specifically, for each iterator i in the range [first, last) the operation op(*i) is performed and the result is assigned to *o, where o is the corresponding output iterator in the range [result, result + (last - first) ). The input and output sequences may coincide, resulting in an in-place transformation.

The algorithm's execution is parallelized as determined by exec.

execThe execution policy to use for parallelization.
firstThe beginning of the input sequence.
lastThe end of the input sequence.
resultThe beginning of the output sequence.
opThe transformation operation.
The end of the output sequence.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratoris a model of Input Iterator and InputIterator's value_type is convertible to UnaryFunction's argument_type.
OutputIteratoris a model of Output Iterator.
UnaryFunctionis a model of Unary Function and UnaryFunction's result_type is convertible to OutputIterator's value_type.
first may equal result, but the range [first, last) shall not overlap the range [result, result + (last - first)) otherwise.

The following code snippet demonstrates how to use transform to negate a range in-place using the thrust::host execution policy for parallelization:

int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
thrust::transform(thrust::host, data, data + 10, data, op); // in-place transformation
// data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8};
See also