count_if() function returns the number of elements in a range that satisfy the condition.
Input: 0 1 2 3 4 5 6 7 8 9 Output: Total no of even numbers is: 5 Input: 2 3 4 5 6 7 8 9 10 11 12 13 Output: Total no of even numbers is: 6
count_if(lower_bound, upper_bound, function)
The count_if function takes three parameters, the first two of which are the first and the last position of the sequence of the elements (where the last position is not included in the range) while the third parameter is the function that takes the element of given sequence one by one as a parameter and returns a boolean value on the basis of condition
specified in that function.
Then, count_if() returns the number of elements in the given sequence for which the comparator function
(third parameter) returns true.
Total no of even numbers is: 5
- Minimum elements inserted in a sorted array to form an Arithmetic progression
- Implementing upper_bound() and lower_bound() for Ordered Set in C++
- How to flatten a Vector of Vectors or 2D Vector in C++
- Queue of Pairs in C++ STL with Examples
- Remove odd frequency characters from the string
- Different ways to use Const with Reference to a Pointer in C++
- std::to_address in C++ with Examples
- Program to create Custom Vector Class in C++
- std::is_trivially_copy_constructible in C/C++
- Difference between Python and C++
- tgamma() method in C/C++ with Examples
- boost::type_traits::is_array Template in C++
- boost is_pointer template in C++
- Wheel Factorization Algorithm
- Stack of Pair in C++ STL with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.