thrust::count
Defined in thrust/count.h
- 
template<typename DerivedPolicy, typename InputIterator, typename EqualityComparable>
 thrust::detail::it_difference_t<InputIterator> thrust::count(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, InputIterator first, InputIterator last, const EqualityComparable &value)
- countfinds the number of elements in- [first,last)that are equal to- value. More precisely,- countreturns the number of iterators- iin- [first, last)such that- *i == value.- The algorithm’s execution is parallelized as determined by - exec.- The following code snippet demonstrates how to use - countto count the number of instances in a range of a value of interest using the- thrust::deviceexecution policy:- #include <thrust/count.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... // put 3 1s in a device_vector thrust::device_vector<int> vec(5,0); vec[1] = 1; vec[3] = 1; vec[4] = 1; // count the 1s int result = thrust::count(thrust::device, vec.begin(), vec.end(), 1); // result == 3 - Parameters
- exec – The execution policy to use for parallelization. 
- first – The beginning of the sequence. 
- last – The end of the sequence. 
- value – The value to be counted. 
 
- Template Parameters
- DerivedPolicy – The name of the derived execution policy. 
- InputIterator – must be a model of Input Iterator and - InputIterator's- value_typemust be a model of must be a model of Equality Comparable.
- EqualityComparable – must be a model of Equality Comparable and can be compared for equality with - InputIterator's- value_type
 
- Returns
- The number of elements equal to - value.