Skip to content

Latest commit

 

History

History
53 lines (30 loc) · 1.32 KB

CppStdCount_if.md

File metadata and controls

53 lines (30 loc) · 1.32 KB

 

 

 

 

 

 

std::count_if is an STL algorithm for counting elements in a container matching a certain predicate. For counting without a predicate use std::count.

 

 

 

 

 

 


#include <algorithm> #include <vector> //From http://www.richelbilderbeek.nl/CppCountNonZeroes.htm int CountNonZeroes(const std::vector<double>& v) {  return std::count_if(     v.begin(),     v.end(),     std::bind2nd(std::not_equal_to<double>(),0.0)); }