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

std::

operators(unordered_multimap)

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

unordered_multimap的关系操作符

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

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



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

☲  参数


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

☉  返回值



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

☣  示例



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

typedef std::unordered_multimap<std::string,int> stringmap;

int main ()
{
  stringmap a = { {"AAPL",100}, {"MSFT",200}, {"GOOG",50}, {"GOOG",20} };
  stringmap b = { {"GOOG",20}, {"MSFT",200}, {"AAPL",100}, {"GOOG",50} };
  stringmap c = { {"GOOG",70}, {"MSFT",200}, {"AAPL",100} };

  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_multimap::equal_range 获取具有特定键的元素范围(公众成员函数)
unordered_multimap::operator= 复制容器内容(公众成员函数)

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