C++ Map 库 - operator== Functionb
描述
C++ 函数 std::map::operator== 测试两个映射是否相等。
声明
以下是 std::map::operator== 函数形式 std::map 头的声明。
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);
参数
m1 − 第一个映射对象。
m2 − 第二个映射对象。
返回值
如果两个映射相等,则返回 true,否则返回 false。
异常
这个函数不会抛出异常。
时间复杂度
线性,即 O(n)
示例
以下示例显示了 std::map::operator== 函数的用法。
#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.

