unordered_set key_eq() function in C++ STL
The unordered_set key_eq() is a built-in function in C++ STL which returns a boolean value according to the comparison. It returns the key equivalence comparison predicate used by the unordered_set. The key equivalence comparison is a predicate that takes two arguments and returns a bool value indicating whether they are equal.
Syntax:
key_equal key_eq() const
Return Value: This method returns the key equality comparison object.
Time Complexity: O(1)
Example 1:
#include <iostream> #include <string> #include <unordered_set> using namespace std; int main() { // unordered_set ms is created unordered_set<string> ms; bool res = ms.key_eq()( "a" , "A" ); cout << "ms.key_eq() is " ; if (res == 1) { cout << "case insensitive" ; } else { // res is 0 as arguments are not equivalent cout << "case sensitive" ; } cout << "\n" ; return 0; } |
Output:
ms.key_eq() is case sensitive
Example 2:
#include <iostream> #include <string> #include <unordered_set> using namespace std; int main() { // unordered_set mp is created unordered_set<string> mp; // the 2 strings are compared bool r = mp.key_eq()( "1000 is a huge number" , "2000 is a huge number" ); cout << "strings are " ; if (r == 1) { cout << "same" ; } else { // the strings are not same so r=0 cout << "not same" ; } cout << "\n" ; return 0; } |
Output:
strings are not same
Contact Us