Namespace placeholders

Facilities for constructing simple functions inline.

Detailed Description

Objects in the thrust::placeholders namespace may be used to create simple arithmetic functions inline in an algorithm invocation. Combining placeholders such as _1 and _2 with arithmetic operations such as + creates an unnamed function object which applies the operation to their arguments. The type of placeholder objects is implementation-defined. The following code snippet demonstrates how to use the placeholders _1 and _2 with thrust::transform to implement the SAXPY computation: #include<thrust/device_vector.h> #include<thrust/transform.h> #include<thrust/functional.h>

intmain() { thrust::device_vector<float>x(4),y(4); x[0]=1; x[1]=2; x[2]=3; x[3]=4;

y[0]=1; y[1]=1; y[2]=1; y[3]=1;

floata=2.0f;

usingnamespacethrust::placeholders;

thrust::transform(x.begin(),x.end(),y.begin(),y.begin(), a*_1+_2 );

//yisnow{3,5,7,9} }