thrust::transform_input_output_iterator#
-
template<typename InputFunction, typename OutputFunction, typename Iterator>
class transform_input_output_iterator : public thrust::iterator_adaptor<transform_input_output_iterator<InputFunction, OutputFunction, Iterator>, Iterator, invoke_result_t<InputFunction, iterator_value_type>, use_default, use_default, transform_input_output_iterator_proxy<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.#include <thrust/iterator/transform_input_output_iterator.h> #include <thrust/device_vector.h> int main() { const size_t size = 4; thrust::device_vector<float> v(size); // 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 auto iter = thrust::make_transform_input_output_iterator(v.begin(), ::cuda::std::negate<float>{}, thrust::square<float>{}); // 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
Public Types
-
using base_type = Base#
The type of iterator this
iterator_adaptor's
adapts
.
Public Functions
-
inline Base const &base() const#
- Returns:
A
const
reference to theBase
iterator thisiterator_adaptor
adapts.
-
using base_type = Base#