thrust::transform
Defined in thrust/transform.h
-
template<typename InputIterator, typename OutputIterator, typename UnaryFunction>
OutputIterator thrust::transform(InputIterator first, InputIterator last, OutputIterator result, UnaryFunction op) This version of
transformapplies 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 iteratoriin the range [first,last) the operationop(*i)is performed and the result is assigned to*o, whereois 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 following code snippet demonstrates how to use
transform#include <thrust/transform.h> #include <thrust/functional.h> int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; thrust::negate<int> op; thrust::transform(data, data + 10, data, op); // in-place transformation // data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8};
Some backends of transform may take advantage knowing if the transformation operation supports copyable arguments.
- Parameters
first – The beginning of the input sequence.
last – The end of the input sequence.
result – The beginning of the output sequence.
op – The transformation operation. Relying on the address of op’s arguments in its implementation is deprecated.
- Template Parameters
InputIterator – is a model of Input Iterator and
InputIterator'svalue_typeis convertible toUnaryFunction'sargument type.OutputIterator – is a model of Output Iterator.
UnaryFunction – is a unary function type which’s return type is convertible to
OutputIterator'svalue_type.
- Returns
The end of the output sequence.
- Pre
firstmay equalresult, but the range[first, last)shall not overlap the range[result, result + (last - first))otherwise.