vector - Standard predicates for STL count_if -


I am using the STL function count_if to calculate all positive values ​​in the vector of doubles. For example, my code is something like this:

  vector & lt; Double & gt; Array (1,1.0) array. Push_back (-1.0); Array.push_back (1.0); Cout & lt; & Lt; Get_if (array.bjin (), array.and (), isPositive);  

Where the function is positive

  bool is posited (double x) {return (x> gt; 0); }  

The following code will return to Code 2. Is there a way above to think that my own fuse is positive? Is there a built-in function that I could use?

Thank you!

standard :: count_if (v.begin (), v.end (), std :: bind1st (std :: less double> (), 0)) is what you want.

If you have already been using Namespace STD , clear version

  count_if (v.begin (), v.end ( ), Bind 1st (lower> double> (), 0));  

All this stuff & lt; Functional & gt; Header, with other standard predicates.


Comments