Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

operators(unordered_map)

函数模板  <unordered_map>
equality (1)
template <class Key, class T, class Hash, class Pred, class Alloc>
  bool operator== ( const unordered_map<Key,T,Hash,Pred,Alloc>& lhs,
                    const unordered_map<Key,T,Hash,Pred,Alloc>& rhs );
inequality (2)
template <class Key, class T, class Hash, class Pred, class Alloc>
  bool operator!= ( const unordered_map<Key,T,Hash,Pred,Alloc>& lhs,
                    const unordered_map<Key,T,Hash,Pred,Alloc>& rhs );

unordered_map的关系操作符

这些重载的全局操作符函数在unordered_map容器lhsrhs之间执行适当的相等或不等比较操作。

相等性比较的过程如下(如果找到确定的结果,则在任意点停止):



注意unordered_map::hash_functionunordered_map::key_eq对象在lhsrhs中应该具有相同的行为。

☲  参数


lhs, rhs
unordered_map容器(分别位于操作符的左边和右边),具有相同的模板形参(Key、Hash、Pred和Alloc)。

☉  返回值



如果条件成立,则为True,否则为false。

☣  示例



// unordered_map comparisons
#include <iostream>
#include <string>
#include <unordered_map>

typedef std::unordered_map<std::string,std::string> stringmap;

int main ()
{
  stringmap a = { {"AAPL","Apple"}, {"MSFT","Microsoft"}, {"GOOG","Google"} };
  stringmap b = { {"MSFT","Microsoft"}, {"GOOG","Google"}, {"AAPL","Apple"} };
  stringmap c = { {"MSFT","Microsoft Corp."}, {"GOOG","Google Inc."}, {"AAPL","Apple Inc."} };

  if (a==b) std::cout << "a and b are equal\n";
  if (b!=c) std::cout << "b and c are not equal\n";

  return 0;
}

输出:
a and b are equal
b and c are not equal

✥ 复杂度



平均情况:线性大小。 最坏情况:大小是二次方。

☣ 迭代器的有效性



不变

🍄  另请参阅



unordered_map::equal_range 获取具有特定键的元素范围(公众成员函数)
unordered_map::operator= 复制容器内容(公众成员函数)

联系我们 免责声明 关于CandCplus 网站地图