◆ sequence() [5/6]

template<typename DerivedPolicy , typename ForwardIterator , typename T >
__host__ __device__ void thrust::sequence ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,

sequence fills the range [first, last) with a sequence of numbers.

For each iterator i in the range [first, last), this version of sequence performs the assignment *i = init + step * (i - first).

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

execThe execution policy to use for parallelization.
firstThe beginning of the sequence.
lastThe end of the sequence.
initThe first value of the sequence of numbers
stepThe difference between consecutive elements.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable, and if x and y are objects of ForwardIterator's value_type, then x + y is defined, and if T is ForwardIterator's value_type, then T(0) is defined.
Tis a model of Assignable, and T is convertible to ForwardIterator's value_type.

The following code snippet demonstrates how to use sequence to fill a range with a sequence of numbers starting from the value 1 with a step size of 3 using the thrust::host execution policy for parallelization:

const int N = 10;
int A[N];
thrust::sequence(thrust::host, A, A + 10, 1, 3);
// A is now {1, 4, 7, 10, 13, 16, 19, 22, 25, 28}
Unlike the similar C++ STL function std::iota, sequence offers no guarantee on order of execution.
See also