Template Function thrust::tabulate(ForwardIterator, ForwardIterator, UnaryOperation)¶
Function Documentation¶
-
template<typename
ForwardIterator
, typenameUnaryOperation
>
voidthrust
::
tabulate
(ForwardIterator first, ForwardIterator last, UnaryOperation unary_op) tabulate
fills the range[first, last)
with the value of a function applied to each element’s index.For each iterator
i
in the range[first, last)
,tabulate
performs the assignment*i = unary_op(i - first)
.The following code snippet demonstrates how to use
tabulate
to generate the firstn
non-positive integers:- Parameters
first
: The beginning of the range.last
: The end of the range.unary_op
: The unary operation to apply.
- Template Parameters
ForwardIterator
: is a model of Forward Iterator, andForwardIterator
is mutable, and ifx
andy
are objects ofForwardIterator's
value_type
, thenx + y
is defined, and ifT
isForwardIterator's
value_type
, thenT(0)
is defined.UnaryOperation
: is a model of Unary Function andUnaryFunction's
result_type
is convertible toOutputIterator's
value_type
.
#include <thrust/tabulate.h> #include <thrust/functional.h> ... const int N = 10; int A[N]; thrust::tabulate(A, A + 10, thrust::negate<int>()); // A is now {0, -1, -2, -3, -4, -5, -6, -7, -8, -9}
- See
thrust::fill
- See
thrust::generate
- See
thrust::sequence