class template
<functional>

std::less_equal

template <class T> struct less_equal;
Function object class for less-than-or-equal-to comparison
Binary function object class whose call returns whether the its first argument compares less than or equal to the second (as returned by operator <=).

Generically, function objects are instances of a class with member function operator() defined. This member function allows the object to be used with the same syntax as a function call.

It is defined with the same behavior as:

1
2
3
template <class T> struct less_equal : binary_function <T,T,bool> {
  bool operator() (const T& x, const T& y) const {return x<=y;}
};
1
2
3
4
5
6
template <class T> struct less_equal {
  bool operator() (const T& x, const T& y) const {return x<=y;}
  typedef T first_argument_type;
  typedef T second_argument_type;
  typedef bool result_type;
};

Objects of this class can be used on standard algorithms such as sort, merge or lower_bound.

Template parameters

T
Type of the arguments to compare by the functional call.
The type shall support the operation (operator<=).

Member types

member typedefinitionnotes
first_argument_typeTType of the first argument in member operator()
second_argument_typeTType of the second argument in member operator()
result_typeboolType returned by member operator()

Member functions

bool operator() (const T& x, const T& y)
Member function returning whether the first argument compares less than or equal to the second (x<=y).

Example

1
2
3
4
5
6
7
8
9
10
11
// less_equal example
#include <iostream>     // std::cout
#include <functional>   // std::less_equal, std::bind2nd
#include <algorithm>    // std::count_if

int main () {
  int numbers[]={25,50,75,100,125};
  int cx = std::count_if (numbers, numbers+5, std::bind2nd(std::less_equal<int>(),100));
  std::cout << "There are " << cx << " elements lower than or equal to 100.\n";
  return 0;
}

Output:

There are 4 elements lower or equal to 100.


See also