List of all members
thrust::constant_iterator< Value, Incrementable, System > Class Template Reference

#include <thrust/iterator/constant_iterator.h>

Detailed Description

template<typename Value, typename Incrementable = use_default, typename System = use_default>
class thrust::constant_iterator< Value, Incrementable, System >

constant_iterator is an iterator which represents a pointer into a range of constant values. This iterator is useful for creating a range filled with the same value without explicitly storing it in memory. Using constant_iterator saves both memory capacity and bandwidth.

The following code snippet demonstrates how to create a constant_iterator whose value_type is int and whose value is 10.

*iter; // returns 10
iter[0]; // returns 10
iter[1]; // returns 10
iter[13]; // returns 10
// and so on...

This next example demonstrates how to use a constant_iterator with the thrust::transform function to increment all elements of a sequence by the same value. We will create a temporary constant_iterator with the function make_constant_iterator function in order to avoid explicitly specifying its type:

int main()
data[0] = 3;
data[1] = 7;
data[2] = 2;
data[3] = 5;
// add 10 to all values in data
thrust::transform(data.begin(), data.end(),
// data is now [13, 17, 12, 15]
return 0;
See also

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