Thrust
List of all members
thrust::transform_input_output_iterator< InputFunction, OutputFunction, Iterator > Class Template Reference

#include <thrust/iterator/transform_input_output_iterator.h>

Detailed Description

template<typename InputFunction, typename OutputFunction, typename Iterator>
class thrust::transform_input_output_iterator< InputFunction, OutputFunction, Iterator >

transform_input_output_iterator is a special kind of iterator which applies transform functions when reading from or writing to dereferenced values. This iterator is useful for algorithms that operate on a type that needs to be serialized/deserialized from values in another iterator, avoiding the need to materialize intermediate results in memory. This also enables the transform functions to be fused with the operations that read and write to the transform_input_output_iterator.

The following code snippet demonstrates how to create a transform_input_output_iterator which performs different transformations when reading from and writing to the iterator.

int main()
{
const size_t size = 4;
// Write 1.0f, 2.0f, 3.0f, 4.0f to vector
thrust::sequence(v.begin(), v.end(), 1);
// Iterator that returns negated values and writes squared values
// Iterator negates values when reading
std::cout << iter[0] << " "; // -1.0f;
std::cout << iter[1] << " "; // -2.0f;
std::cout << iter[2] << " "; // -3.0f;
std::cout << iter[3] << "\n"; // -4.0f;
// Write 1.0f, 2.0f, 3.0f, 4.0f to iterator
thrust::sequence(iter, iter + size, 1);
// Values were squared before writing to vector
std::cout << v[0] << " "; // 1.0f;
std::cout << v[1] << " "; // 4.0f;
std::cout << v[2] << " "; // 9.0f;
std::cout << v[3] << "\n"; // 16.0f;
}
See also
make_transform_input_output_iterator

The documentation for this class was generated from the following file: