count_if :返回區間中滿足指定條件的元素數目。
template<class InputIterator, class Predicate> typename iterator_traits<InputIterator>::difference_type count_if( InputIterator _First, InputIterator _Last, Predicate _Pred ); |
Parameters
_First 輸入迭代器,指向將被搜索的區間第一個元素的位置。
_Last 輸入迭代器,指向將被搜索的區間最後一個元素後面的。
_Pred 用戶自定義的 predicate function object ,定義了元素被計數需滿足的條件。 predicate 只帶一個參數,返回 true 或 false.
Return Value
滿足斷言(predicate)指定條件的元素數。
Remarks
這個模板函數是書法count的泛化版本,用斷言指定的條件代替等於一個指定的值。
Example
Output
|
|
v1 = ( 10 20 10 40 10 ) The number of elements in v1 greater than 10 is: 2. |
Requirements
Header: <algorithm>