## count
## Prototype
template <class InputIterator, class EqualityComparable> iterator_traits<InputIterator>::difference_type count(InputIterator first, InputIterator last, const EqualityComparable& value); template <class InputIterator, class EqualityComparable, class Size> void count(InputIterator first, InputIterator last, const EqualityComparable& value, Size& n); ## Description
The second version of Both interfaces are currently supported [1], for reasons of backward compatibility, but eventually the older version will be removed. ## DefinitionDefined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h. ## Requirements on typesFor the first version, which takes three arguments: -
`InputIterator` is a model of InputIterator. -
`EqualityComparable` is a model of EqualityComparable. -
`InputIterator` 's value type is a model of EqualityComparable. -
An object of
`InputIterator` 's value type can be compared for equality with an object of type`EqualityComparable` .
For the second version, which takes four arguments: -
`InputIterator` is a model of InputIterator. -
`EqualityComparable` is a model of EqualityComparable. -
`Size` is an integral type that can hold values of`InputIterator` 's distance type. -
`InputIterator` 's value type is a model of EqualityComparable. -
An object of
`InputIterator` 's value type can be compared for equality with an object of type`EqualityComparable` .
## Preconditions-
`[first, last)` is a valid range.
For the second version: -
`[first, last)` is a valid range. -
`n` plus the number of elements equal to`value` does not exceed the maximum value of type`Size` .
## ComplexityLinear. Exactly ## Exampleint main() { int A[] = { 2, 0, 4, 6, 0, 3, 1, -7 }; const int N = sizeof(A) / sizeof(int); cout << "Number of zeros: " << count(A, A + N, 0) << endl; } ## Notes[1] The new ## See also |