find_if
#
Overloads#
find_if(exec, first, last, pred)
#
-
template<typename DerivedPolicy, typename InputIterator, typename Predicate>
InputIterator thrust::find_if( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- Predicate pred,
find_if
returns the first iteratori
in the range[first, last)
such thatpred(*i)
istrue
orlast
if no such iterator exists.The algorithm’s execution is parallelized as determined by
exec
.#include <thrust/find.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... struct greater_than_four { __host__ __device__ bool operator()(int x) { return x > 4; } }; struct greater_than_ten { __host__ __device__ bool operator()(int x) { return x > 10; } }; ... thrust::device_vector<int> input(4); input[0] = 0; input[1] = 5; input[2] = 3; input[3] = 7; thrust::device_vector<int>::iterator iter; iter = thrust::find_if(thrust::device, input.begin(), input.end(), greater_than_four()); // returns input.first() + 1 iter = thrust::find_if(thrust::device, input.begin(), input.end(), greater_than_ten()); // returns input.end()
See also
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – Beginning of the sequence to search.
last – End of the sequence to search.
pred – A predicate used to test range elements.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator.
Predicate – is a model of Predicate.
- Returns:
The first iterator
i
such thatpred(*i)
istrue
, orlast
.
find_if(first, last, pred)
#
-
template<typename InputIterator, typename Predicate>
InputIterator thrust::find_if( - InputIterator first,
- InputIterator last,
- Predicate pred,
find_if
returns the first iteratori
in the range[first, last)
such thatpred(*i)
istrue
orlast
if no such iterator exists.#include <thrust/find.h> #include <thrust/device_vector.h> struct greater_than_four { __host__ __device__ bool operator()(int x) { return x > 4; } }; struct greater_than_ten { __host__ __device__ bool operator()(int x) { return x > 10; } }; ... thrust::device_vector<int> input(4); input[0] = 0; input[1] = 5; input[2] = 3; input[3] = 7; thrust::device_vector<int>::iterator iter; iter = thrust::find_if(input.begin(), input.end(), greater_than_four()); // returns input.first() + 1 iter = thrust::find_if(input.begin(), input.end(), greater_than_ten()); // returns input.end()
See also
See also
See also
- Parameters:
first – Beginning of the sequence to search.
last – End of the sequence to search.
pred – A predicate used to test range elements.
- Template Parameters:
InputIterator – is a model of Input Iterator.
Predicate – is a model of Predicate.
- Returns:
The first iterator
i
such thatpred(*i)
istrue
, orlast
.