operator<= (<utility>)
Тесты, если объект пар слева от оператора, меньше или равно возражают паре с правой стороны.
template<Class Type>
bool operator<=(
const Type& _Left,
const Type& _Right
);
template<class Type1, class Type2>
bool operator<=(
const pair<Type1, Type2>& _Left,
const pair<Type1, Type2>& _Right
);
Параметры
_Left
Объект типа pair в левой части оператора._Right
Объект типа pair в правой части оператора.
Возвращаемое значение
Если pairtrue слева от оператора, меньше или равно pair в правой части оператора; в противном случае false.
Заметки
При сравнении значений пар элементов первые 2 пар имеющие наивысший приоритет.Если они отличаются, то результат сравнения их что в результате сравнения пар.Если значения первых элементов не различаются, то сравниваются значения второго элементов и результат их сравнения взят в результате сравнения пар.
Пример
// utility_op_le.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>
int main( )
{
using namespace std;
pair <int, double> p1, p2, p3, p4;
p1 = make_pair ( 10, 2.22e-1 );
p2 = make_pair ( 100, 1.11e-1 );
p3 = make_pair ( 10, 1.11e-1 );
p4 = make_pair ( 10, 2.22e-1 );
cout.precision ( 3 );
cout << "The pair p1 is: ( " << p1.first << ", "
<< p1.second << " )." << endl;
cout << "The pair p2 is: ( " << p2.first << ", "
<< p2.second << " )." << endl;
cout << "The pair p3 is: ( " << p3.first << ", "
<< p3.second << " )." << endl;
cout << "The pair p4 is: ( " << p4.first << ", "
<< p4.second << " )." << endl << endl;
if ( p1 <= p2 )
cout << "The pair p1 is less than or equal to the pair p2." << endl;
else
cout << "The pair p1 is greater than the pair p2." << endl;
if ( p1 <= p3 )
cout << "The pair p1 is less than or equal to the pair p3." << endl;
else
cout << "The pair p1 is greater than the pair p3." << endl;
if ( p1 <= p4 )
cout << "The pair p1 is less than or equal to the pair p4." << endl;
else
cout << "The pair p1 is greater than the pair p4." << endl;
}
Требования
заголовок: <utility>
std пространство имен: