1 #include <thrust/iterator/constant_iterator.h>
2 #include <thrust/transform.h>
3 #include <thrust/functional.h>
4 #include <thrust/device_vector.h>
5 #include <thrust/copy.h>
6 #include <iterator>
7 #include <iostream>
8 
main(void)9 int main(void)
10 {
11     thrust::device_vector<int> data(4);
12     data[0] = 3;
13     data[1] = 7;
14     data[2] = 2;
15     data[3] = 5;
16 
17     // add 10 to all values in data
18     thrust::transform(data.begin(), data.end(),
19                       thrust::constant_iterator<int>(10),
20                       data.begin(),
21                       thrust::plus<int>());
22 
23     // data is now [13, 17, 12, 15]
24 
25     // print result
26     thrust::copy(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, "\n"));
27 
28     return 0;
29 }
30