C++ unordered_set - key_eq() Function
The C++ unordered_set::key_eq function returns the key equivalence comparison predicate used by the unordered_set 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_set::key_eq().
#include <iostream> #include <unordered_set> using namespace std; int main (){ unordered_set<string> uSet; bool case_insensitive = uSet.key_eq()("alpha", "Alpha"); cout<<"uSet.key_eq() is "; cout<<(case_insensitive? "case insensitive." : "case sensitive."); return 0; }
The output of the above code will be:
uSet.key_eq() is case sensitive.
❮ C++ <unordered_set> Library