fill_n#

Overloads#

fill_n(exec, first, n, value)#

template<typename DerivedPolicy, typename OutputIterator, typename Size, typename T>
OutputIterator thrust::fill_n(
const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
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.

The algorithm’s execution is parallelized as determined by exec.

The following code snippet demonstrates how to use fill to set a thrust::device_vector’s elements to a given value using the thrust::device execution policy for parallelization:

#include <thrust/fill.h>
#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>
...
thrust::device_vector<int> v(4);
thrust::fill_n(thrust::device, v.begin(), v.size(), 137);

// v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137

See also

fill

Parameters:
  • exec – The execution policy to use for parallelization.

  • first – The beginning of the sequence.

  • n – The size of the sequence.

  • value – The value to be copied.

Template Parameters:
  • DerivedPolicy – The name of the derived execution policy.

  • OutputIterator – is a model of Output Iterator.

  • T – is a model of Assignable, and T's value_type is convertible to a type in OutputIterator's set of value_type.

Returns:

first + n

fill_n(first, n, value)#

template<typename OutputIterator, typename Size, typename T>
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.

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>
#include <thrust/device_vector.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

fill

Parameters:
  • first – The beginning of the sequence.

  • n – The size of the sequence.

  • value – The value to be copied.

Template Parameters:
  • OutputIterator – is a model of Output Iterator.

  • T – is a model of Assignable, and T's value_type is convertible to a type in OutputIterator's set of value_type.

Returns:

first + n