测试,如果运算符左侧的对象包含对小于右侧对象。
template<class Type1, class Type2>
bool operator<(
const pair<Type1, Type2>& _Left,
const pair<Type1, Type2>& _Right
);
参数
_Left
运算符左侧的 pair 类型的对象。_Right
类型与运算符右侧的 pair 对象。
返回值
true,如果运算符左侧的 pair 比与运算符右侧的 pair 强小于;为 false。
备注
_Left pair 对象比 _Right pair 对象强视为小于 _Left 是否小于并不等于 _Right.
在对两对值的比较,第一个元素具有最高优先级。 如果协定类型不同,作为对的比较,则它们的比较结果的操作。 如果第一个元素的值不是不同的,则第二个元素的值比较作为对的比较,并且,它们的比较结果的操作。
示例
// utility_op_lt.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>
int main( )
{
using namespace std;
pair <int, double> p1, p2, p3;
p1 = make_pair ( 10, 2.22e-1 );
p2 = make_pair ( 100, 1.11e-1 );
p3 = make_pair ( 10, 1.11e-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 << endl;
if ( p1 < p2 )
cout << "The pair p1 is less than the pair p2." << endl;
else
cout << "The pair p1 is not less than the pair p2." << endl;
if ( p1 < p3 )
cout << "The pair p1 is less than the pair p3." << endl;
else
cout << "The pair p1 is not less than the pair p3." << endl;
}
要求
页眉: <实用工具>
命名空间: std