operator== (unordered_set)

测试在运算符的左边 unordered_set 对象是否与右侧的 unordered_set 对象相等。

bool operator==(
   const unordered_set <Key, Hash, Pred, Allocator>& _Left,
   const unordered_set <Key, Hash, Pred, Allocator>& _Right
);

参数

  • _Left
    unordered_set 类型的对象。

  • _Right
    unordered_set 类型的对象。

返回值

true,如果 unordered_sets 相等;false,如果它们不相等。

备注

在 unordered_set 对象之间的比较不影响的是受这些存储元素的任意顺序的。 两 unordered_sets 相等;如果它们具有相同元素数目,并在一个容器的元素是元素的排列在另一个容器的。 否则为不相等。

示例

 
// unordered_set_eq.cpp 
// compile by using: cl.exe /EHsc /nologo /W4 /MTd 
#include <unordered_set> 
#include <iostream> 
#include <ios>

int main() 
{ 
    using namespace std;

    unordered_set<char> c1, c2, c3;

    c1.insert('a'); 
    c1.insert('b'); 
    c1.insert('c'); 

    c2.insert('c'); 
    c2.insert('a'); 
    c2.insert('d'); 

    c3.insert('c'); 
    c3.insert('a'); 
    c3.insert('b'); 

   cout << boolalpha;
   cout << "c1 == c2: " << (c1 == c2) << endl; 
   cout << "c1 == c3: " << (c1 == c3) << endl; 
   cout << "c2 == c3: " << (c2 == c3) << endl; 

    return (0); 
} 

输出:

c1 == c2: false

c1 == c3: true

c2 == c3: false

要求

标头: <unordered_set>

命名空间: std

请参见

参考

标准模板库