thrust

◆ fill_n() [2/2]

template<typename OutputIterator , typename Size , typename T >
__host__ __device__ OutputIterator thrust::fill_n ( OutputIterator  first,
Size  n,
const T &  value 
)

fill_n assigns the value value to every element in the range [first, first+n). That is, for every iterator i in [first, first+n), it performs the assignment *i = value.

Parameters
firstThe beginning of the sequence.
nThe size of the sequence.
valueThe value to be copied.
Returns
first + n
Template Parameters
OutputIteratoris a model of Output Iterator.
Tis a model of Assignable, and T's value_type is convertible to a type in OutputIterator's set of value_type.

The following code snippet demonstrates how to use fill to set a thrust::device_vector's elements to a given value.

#include <thrust/fill.h>
...
thrust::device_vector<int> v(4);
thrust::fill_n(v.begin(), v.size(), 137);
// v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137
See also
http://www.sgi.com/tech/stl/fill_n.html
fill
uninitialized_fill_n