Template Function thrust::count(InputIterator, InputIterator, const EqualityComparable&)¶
Function Documentation¶
-
template<typename
InputIterator, typenameEqualityComparable>
thrust::iterator_traits<InputIterator>::difference_typethrust::count(InputIterator first, InputIterator last, const EqualityComparable &value) countfinds the number of elements in[first,last)that are equal tovalue. More precisely,countreturns the number of iteratorsiin[first, last)such that*i == value.The following code snippet demonstrates how to use
countto count the number of instances in a range of a value of interest.#include <thrust/count.h> #include <thrust/device_vector.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(vec.begin(), vec.end(), 1); // result == 3
- Return
The number of elements equal to
value.- Parameters
first: The beginning of the sequence.last: The end of the sequence.value: The value to be counted.
- Template Parameters
InputIterator: must be a model of Input Iterator andInputIterator'svalue_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 withInputIterator'svalue_type