operator<= (map)
测试,如果运算符左侧的映射对象小于或等于右侧的映射对象。
bool operator<=(
const map <Key, Type, Traits, Allocator>& _Left,
const map <Key, Type, Traits, Allocator>& _Right
);
参数
_Left
类型 映射对象。_Right
类型 映射对象。
返回值
true,如果运算符左侧的映射是小于或等于映射与运算符的右侧;为 false。
备注
在映射对象之间的比较基于元素的一种比较成对。 小于或等于两个对象之间的关系。根据第一个不相等对比较元素。
示例
// map_op_le.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
map <int, int> m1, m2, m3, m4;
int i;
typedef pair <int, int> Int_Pair;
for ( i = 1 ; i < 3 ; i++ )
{
m1.insert ( Int_Pair ( i, i ) );
m2.insert ( Int_Pair ( i, i * i ) );
m3.insert ( Int_Pair ( i, i - 1 ) );
m4.insert ( Int_Pair ( i, i ) );
}
if ( m1 <= m2 )
cout << "The map m1 is less than or equal to the map m2." << endl;
else
cout << "The map m1 is greater than the map m2." << endl;
if ( m1 <= m3 )
cout << "The map m1 is less than or equal to the map m3." << endl;
else
cout << "The map m1 is greater than the map m3." << endl;
if ( m1 <= m4 )
cout << "The map m1 is less than or equal to the map m4." << endl;
else
cout << "The map m1 is greater than the map m4." << endl;
}
要求
标头: <map>
命名空间: std