cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : Miscellaneous : functional : less_equal
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
functional
iterator
memory
utility
functional
binary_function
unary_function
operator classes:
· divides
· equal_to
· greater
· greater_equal
· less
· less_equal
· logical_and
· logical_not
· logical_or
· minus
· modulus
· multiplies
· negate
· not_equal_to
· plus
adaptor functions:
· bind1st
· bind2nd
· mem_fun
· mem_fun_ref
· not1
· not2
· ptr_fun
types:
· binary_negate
· binder1st
· binder2nd
· const_mem_fun1_ref_t
· const_mem_fun1_t
· const_mem_fun_ref_t
· const_mem_fun_t
· mem_fun1_ref_t
· mem_fun1_t
· mem_fun_ref_t
· mem_fun_t
· pointer_to_binary_funct...
· pointer_to_unary_function
· unary_negate

-

less_equal class template
template <class T> struct less_equal;
<functional>

Function object class for less-than-or-equal-to comparison

This class defines function objects for the "less than or equal to" comparison operation (<=).

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 regular function call, and therefore it can be used in templates instead of a pointer to a function.

less_equal has its operator() member defined such that it returns true if its first argument compares lower than or equal to the second one using operator<, and false otherwise.

This class is derived from binary_function and is defined as:

template <class T> struct less_equal : binary_function <T,T,bool> {
  T operator() (const T& x, const T& y) const
    {return x<=y;}
};

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

Members

T operator() (const T& x, const T& y)
Member function returning the result of the comparison x<=y.

Example

// less_equal example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

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

Output:


There are 4 elements lower or equal to 100.

See also

equal_to Function object class for equality comparison (class template)
not_equal_to Function object class for non-equality comparison (class template)
greater Function object class for greater-than inequality comparison (class template)
less Function object class for less-than inequality comparison (class template)
greater_equal Function object class for greater-than-or-equal-to comparison (class template)
binary_function Binary function object base class (class template)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us