C++ Standard Library C++ STL Library

C++ unordered_map - key_eq() Function



The C++ unordered_map::key_eq function returns the key equivalence comparison predicate used by the unordered_map 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_map::key_eq().

#include <iostream>
#include <unordered_map>
using namespace std;
 
int main (){
  unordered_map<string, string> uMap;

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

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

  return 0;
}

The output of the above code will be:

uMap.key_eq() is case sensitive.

❮ C++ <unordered_map> Library

5