operator==
描述 (Description)
C ++函数std::map::operator==测试两个映射是否相等。
声明 (Declaration)
以下是std :: map :: operator == function form std :: map header的声明。
C++98
template <class Key, class T, class Compare, class Alloc>
bool operator== ( const map<Key,T,Compare,Alloc>& m1,
const map<Key,T,Compare,Alloc>& m2);
参数 (Parameters)
m1 - 第一个地图对象。
m2 - 第二个地图对象。
返回值
如果两个map都相等则返回true,否则返回false。
异常 (Exceptions)
此函数不会抛出异常。
时间复杂
线性即O(n)
例子 (Example)
以下示例显示了std :: map :: operator == function的用法。
#include <iostream>
#include <map>
using namespace std;
int main(void) {
map<char, int> m1;
map<char, int> m2;
if (m1 == m2)
cout << "Both maps are equal." << endl;
m1.emplace('a', 1);
if (!(m1 == m2))
cout << "Both maps are not equal." << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Both maps are equal.
Both maps are not equal.