Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::less_equal

 

std::less_equal is an STL predicate to perform operator<= on two values.

 

#include <algorithm>
#include <cassert>
#include <functional>
#include <vector>

int main()
{
  //Create a std::vector with values {0,1,2,3,4,5}
  std::vector<int> v;
  for (int i = 0; i!=6; ++i) v.push_back(i);

  //Count the values less or equal to two
  const int n
    = std::count_if(
        v.begin(),v.end(),
        std::bind2nd(std::less_equal<int>(),2));

  //Assume there are three values less or equal to two
  assert(n==3);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict