function template
<unordered_set>

std::operators (unordered_set)

equality (1)
template <class Key, class Hash, class Pred, class Alloc>  bool operator== ( const unordered_set<Key,Hash,Pred,Alloc>& lhs,                    const unordered_set<Key,Hash,Pred,Alloc>& rhs );
inequality (2)
template <class Key, class Hash, class Pred, class Alloc>  bool operator!= ( const unordered_set<Key,Hash,Pred,Alloc>& lhs,                    const unordered_set<Key,Hash,Pred,Alloc>& rhs );
Relational operators for unordered_set
These overloaded global operator functions perform the appropriate equality or inequality comparison operation between the unordered_set containers lhs and rhs.

The procedure for the equality comparison is as follows (stopping at any point if the procedure finds a conclusive answer):
  • First, the sizes are compared.
  • Then, each element in one of the containers is looked for in the other.

Note that the unordered_set::hash_function and unordered_set::key_eq objects are expected to have the same behavior in both lhs and rhs.

Parameters

lhs, rhs
unordered_set containers (to the left- and right-hand side of the operator, respectively), having both the same template parameters (Key, Hash, Pred and Alloc).

Return Value

true if the condition holds, and false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// unordered_set comparisons
#include <iostream>
#include <string>
#include <unordered_set>

int main ()
{
  std::unordered_set<std::string>
    a = {"AAPL","MSFT","GOOG"},
    b = {"MSFT","GOOG","AAPL"},
    c = {"MSFT","GOOG","AAPL","ORCL"};

  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;
}

Output:
a and b are equal
b and c are not equal


Complexity

Average case: linear in size.
Worst case: quadratic in size.

Iterator validity

No changes.

See also