Template Function thrust::transform(InputIterator1, InputIterator1, InputIterator2, OutputIterator, BinaryFunction)

Function Documentation

template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryFunction>
OutputIterator thrust::transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryFunction op)

This version of transform applies a binary function to each pair of elements from two input sequences and stores the result in the corresponding position in an output sequence. Specifically, for each iterator i in the range [first1, last1) and j = first + (i - first1) in the range [first2, last2) the operation op(*i,*j) 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 following code snippet demonstrates how to use

transform
Return

The end of the output sequence.

Pre

first1 may equal result, but the range [first1, last1) shall not overlap the range [result, result + (last1 - first1)) otherwise.

Pre

first2 may equal result, but the range [first2, first2 + (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise.

Parameters
  • first1: The beginning of the first input sequence.

  • last1: The end of the first input sequence.

  • first2: The beginning of the second input sequence.

  • result: The beginning of the output sequence.

  • op: The tranformation operation.

Template Parameters
  • InputIterator1: is a model of Input Iterator and InputIterator1's value_type is convertible to BinaryFunction's first_argument_type.

  • InputIterator2: is a model of Input Iterator and InputIterator2's value_type is convertible to BinaryFunction's second_argument_type.

  • OutputIterator: is a model of Output Iterator.

  • BinaryFunction: is a model of Binary Function and BinaryFunction's result_type is convertible to OutputIterator's value_type.

#include <thrust/transform.h>
#include <thrust/functional.h>

int input1[6] = {-5,  0,  2,  3,  2,  4};
int input2[6] = { 3,  6, -2,  1,  2,  3};
int output[6];

thrust::plus<int> op;

thrust::transform(input1, input1 + 6, input2, output, op);

// output is now {-2,  6,  0,  4,  4,  7};

See

http://www.sgi.com/tech/stl/transform.html