thrust::tabulate_output_iterator
Defined in thrust/iterator/tabulate_output_iterator.h
-
template<typename BinaryFunction, typename System = use_default, typename DifferenceT = ptrdiff_t>
class tabulate_output_iterator : public detail::tabulate_output_iterator_base<BinaryFunction, use_default, ptrdiff_t> tabulate_output_iterator
is a special kind of output iterator which, whenever a value is assigned to a dereferenced iterator, calls the given callable with the index that corresponds to the offset of the dereferenced iterator and the assigned value.The following code snippet demonstrated how to create a
tabulate_output_iterator
which prints the index and the assigned value.#include <thrust/iterator/tabulate_output_iterator.h> // note: functor inherits form binary function struct print_op { __host__ __device__ void operator()(int index, float value) const { printf("%d: %f\n", index, value); } }; int main() { auto tabulate_it = thrust::make_tabulate_output_iterator(print_op{}); tabulate_it[0] = 1.0f; // prints: 0: 1.0 tabulate_it[1] = 3.0f; // prints: 1: 3.0 tabulate_it[9] = 5.0f; // prints: 9: 5.0 }
See also
make_tabulate_output_iterator