Skip to content

Latest commit

 

History

History
13 lines (10 loc) · 521 Bytes

count_if.md

File metadata and controls

13 lines (10 loc) · 521 Bytes

count_if

Description : Returns the number of elements in the range [first, last) satisfying specific criteria(counts the elements that are equal to value).

Example:

    std::vector<int> v{ 1, 2, 3, 4, 4, 3, 7, 8, 9, 10 };
 
    // use a lambda expression to count elements divisible by 3.
    int num_items3 = std::count_if(v.begin(), v.end(), [](int i){return i % 3 == 0;});
    std::cout << "number divisible by three: " << num_items3 << '\n';

Run Code