Sdílet prostřednictvím


less_equal – struktura

Binárního predikátu, která provádí operace méně než nebo rovno (operator<=) na jeho argumenty.

template<class Type = void>
   struct less_equal : public binary_function <Type, Type, bool> 
   {
      bool operator()(
         const Type& Left, 
         const Type& Right
      ) const;
   };

// specialized transparent functor for operator<=
template<>
   struct less_equal<void>
   {
      template<class Type1, class Type2>
      auto operator()(Type1&& Left, Type2&& Right) const
         -> decltype(std::forward<Type1>(Left)
            <= std::forward<Type2>(Right));
   };

Parametry

  • Type, Type1, Type2
    Libovolný typ, který podporuje operator<= , která má určený nebo odvozené typy operandy.

  • Left
    Levý operand operace méně než nebo rovno.Unspecialized šablona má lvalue odkaz argument typu Type.Specializované šablony perfektní předávání lvalue a argumenty rvalue odkaz odvozen typ Type1.

  • Right
    Pravý operand operace méně než nebo rovno.Unspecialized šablona má lvalue odkaz argument typu Type.Specializované šablony perfektní předávání lvalue a argumenty rvalue odkaz odvozen typ Type2.

Vrácená hodnota

The result of Left<=Right.Specializované šablony perfektní předávání výsledků, které má typ vrácené operator<=.

Poznámky

Binárního predikátu less_equal<Type> poskytuje přísné slabé objednání sady hodnot prvků typu Type do tříd ekvivalence, pokud tento typ splňuje standardní matematické předpoklady pro právě tak objednáno.Specializace pro každý typ ukazatel výnosu z celkové pořadí prvků, v tom, že všechny prvky různých hodnot jsou uspořádány ve vztahu k sobě navzájem.

Příklad

// functional_less_equal.cpp
// compile with: /EHsc
#define _CRT_RAND_S
#include <stdlib.h>
#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;
   unsigned int randomNumber;

   int i;
   for ( i = 0 ; i < 5 ; i++ )
   {
      if ( rand_s( &randomNumber ) == 0 )
      {
         // Convert the random number to be between 1 - 50000
         // This is done for readability purposes
         randomNumber = ( unsigned int) ((double)randomNumber / 
            (double) UINT_MAX * 50000) + 1;

         v1.push_back( randomNumber );
      }
   }
   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;
}

Výstup ukázky

Original vector v1 = ( 31247 37154 48755 15251 6205 2836 2836 2836 )
Sorted vector v1 = ( 2836 2836 2836 6205 15251 31247 37154 48755 )

Požadavky

Záhlaví: <functional>

Obor názvů: std

Viz také

Referenční dokumentace

Standardní knihovna šablon