C++ Standard Library C++ STL Library

C++ unordered_multiset - key_eq() Function



The C++ unordered_multiset::key_eq function returns the key equivalence comparison predicate used by the unordered_multiset container. The key equivalence comparison is a predicate that takes the value of two elements as arguments and returns a bool value indicating whether they are to be considered equivalent. By default, it is equal_to<key_type>, which returns the same as applying the equal-to operator (==) to the arguments.

Syntax

key_equal key_eq() const;

Parameters

No parameter is required.

Return Value

The key equality comparison object.

Time Complexity

Constant i.e, Θ(1)

Example:

The example below shows the usage of unordered_multiset::key_eq().

#include <iostream>
#include <unordered_set>
using namespace std;
 
int main (){
  unordered_multiset<string> uMSet;

  bool case_insensitive = uMSet.key_eq()("alpha", "Alpha");

  cout<<"uMSet.key_eq() is ";
  cout<<(case_insensitive? "case insensitive." : "case sensitive.");

  return 0;
}

The output of the above code will be:

uMSet.key_eq() is case sensitive.

❮ C++ <unordered_set> Library