thrust::transform_if
Defined in thrust/transform.h
- 
template<typename InputIterator1, typename InputIterator2, typename ForwardIterator, typename UnaryFunction, typename Predicate>
 ForwardIterator thrust::transform_if(InputIterator1 first, InputIterator1 last, InputIterator2 stencil, ForwardIterator result, UnaryFunction op, Predicate pred)
- This version of - transform_ifconditionally applies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence if the corresponding position in a stencil sequence satisfies a predicate. Otherwise, the corresponding position in the output sequence is not modified.- Specifically, for each iterator - iin the range- [first, last)the predicate- pred(*s)is evaluated, where- sis the corresponding input iterator in the range- [stencil, stencil + (last - first) ). If this predicate evaluates to- true, the result of- op(*i)is assigned to- *o, where- ois the corresponding output iterator in the range- [result, result + (last - first) ). Otherwise,- op(*i)is not evaluated and no assignment occurs. The input and output sequences may coincide, resulting in an in-place transformation.- The following code snippet demonstrates how to use - transform_if:- #include <thrust/transform.h> #include <thrust/functional.h> int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; int stencil[10] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; thrust::negate<int> op; ::cuda::std::identity identity; thrust::transform_if(data, data + 10, stencil, data, op, identity); // in-place transformation // data is now {5, 0, -2, -3, -2, 4, 0, -1, -2, 8}; - See also - thrust::transform - Parameters
- first – The beginning of the input sequence. 
- last – The end of the input sequence. 
- stencil – The beginning of the stencil sequence. 
- result – The beginning of the output sequence. 
- op – The transformation operation. Relying on the address of op’s arguments in its implementation is deprecated. 
- pred – The predicate operation. Relying on the address of pred’s arguments in its implementation is deprecated. 
 
- Template Parameters
- InputIterator1 – is a model of Input Iterator and - InputIterator1's- value_typeis convertible to- UnaryFunction'sargument type.
- InputIterator2 – is a model of Input Iterator and - InputIterator2's- value_typeis convertible to- Predicate'sargument type.
- ForwardIterator – is a model of Forward Iterator. 
- UnaryFunction – The function’s return type must be convertible to - OutputIterator's- value_type.
- Predicate – is a model of Predicate. 
 
- Returns
- The end of the output sequence. 
- Pre
- firstmay equal- result, but the range- [first, last)shall not overlap the range- [result, result + (last - first))otherwise.
- Pre
- stencilmay equal- result, but the range- [stencil, stencil + (last - first))shall not overlap the range- [result, result + (last - first))otherwise.