Thrust
|
#include <thrust/iterator/counting_iterator.h>
counting_iterator
is an iterator which represents a pointer into a range of sequentially changing values. This iterator is useful for creating a range filled with a sequence without explicitly storing it in memory. Using counting_iterator
saves memory capacity and bandwidth.
The following code snippet demonstrates how to create a counting_iterator
whose value_type
is int
and which sequentially increments by 1
.
This next example demonstrates how to use a counting_iterator
with the thrust::copy_if
function to compute the indices of the non-zero elements of a device_vector
. In this example, we use the make_counting_iterator
function to avoid specifying the type of the counting_iterator
.