generate
assigns the result of invoking gen
, a function object that takes no arguments, to each element in the range [first,last)
.
The algorithm's execution is parallelized as determined by exec
.
- Parameters
-
exec | The execution policy to use for parallelization. |
first | The first element in the range of interest. |
last | The last element in the range of interest. |
gen | A function argument, taking no parameters, used to generate values to assign to elements in the range [first,last) . |
- Template Parameters
-
DerivedPolicy | The name of the derived execution policy. |
ForwardIterator | is a model of Forward Iterator, and ForwardIterator is mutable. |
Generator | is a model of Generator, and Generator's result_type is convertible to ForwardIterator's value_type . |
The following code snippet demonstrates how to fill a host_vector
with random numbers, using the standard C library function rand
using the thrust::host
execution policy for parallelization:
#include <cstdlib>
...
thrust::host_vector<int> v(10);
srand(13);
- See also
- generate_n
-
https://en.cppreference.com/w/cpp/algorithm/generate