如果在运算符的左边对对象与右侧,对对象小于测试。
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。
备注
_Leftpair 对象与 _Rightpair 对象强被视为低于 _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;
}
要求
标头: <utility>
命名空间: std