Export (0) Print
Expand All

less_equal Struct

A binary predicate that tests whether a value of a specified type is less than or equal to another value of that type.

template<class Type> 
   struct less_equal : public binary_function <Type, Type, bool>  
   { 
      bool operator()( 
         const Type& _Left,  
         const Type& _Right 
      ) const; 
   };

_Left

The left operand of type Type in the inequality to be tested.

_Right

The right operand of type Type in the inequality to be tested.

true if _Left <= _Right; false if _Left > _Right.

The binary predicate less_equal<Type> provides a strict weak ordering of a set of element values of type Type into equivalence classes if and only if this Type satisfies the standard mathematical requirements for being so ordered. The specializations for any pointer type yield a total ordering of elements in that all elements of distinct values are ordered with respect to each other.

// functional_less_equal.cpp
// compile with: /EHsc
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <iostream>

int main( )
{
   using namespace std;
   vector <int> v1;
   vector <int>::iterator Iter1;
   vector <int>::reverse_iterator rIter1;

   int i;
   for ( i = 0 ; i < 5 ; i++ )
   {
      v1.push_back( rand( ) );
   }
   for ( i = 0 ; i < 3 ; i++ )
   {
      v1.push_back( 2836 );
   }

   cout << "Original vector v1 = ( " ;
   for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
      cout << *Iter1 << " ";
   cout << ")" << endl;

   // To sort in ascending order,
   // use the binary predicate less_equal<int>( )
   sort( v1.begin( ), v1.end( ), less_equal<int>( ) );
   cout << "Sorted vector v1 = ( " ;
   for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
      cout << *Iter1 << " ";
   cout << ")" << endl;
}

Original vector v1 = ( 41 18467 6334 26500 19169 2836 2836 2836 )
Sorted vector v1 = ( 41 2836 2836 2836 6334 18467 19169 26500 )

Header: <functional>

Namespace: std

Community Additions

ADD
Show:
© 2014 Microsoft