unordered_multiset key_eq() function in C++ STL
The unordered_multiset::key_eq() is a built-in function in C++ STL which returns a boolean value according to the comparison. It depends on the key equivalence comparison predicate used by the unordered_multiset container. The key equivalence comparison is a predicate which takes two arguments and returns a boolean value indicating whether they are to be considered equivalent. It returns true if they are equivalent else it returns false. It is adopted by the container on construction and is similar to the (==) operator used in the comparison. Syntax:
unordered_multiset_name.key_eq()(args1, args2)
Parameter: The function accepts two mandatory parameters args1 and args2, between whom the comparison is to be done. The data_type is same as that of the unordered_multiset. Return Value: The function returns a boolean value. Below programs illustrate the unordered_multiset::key_eq() function: Program 1:
CPP
// CPP program to illustrate the // unordered_multiset::key_eq() function #include <iostream> #include <string> #include <unordered_set> using namespace std; int main() { unordered_multiset<string> sampleSet; bool answer = sampleSet.key_eq()( "Beginner" , "Beginner" ); // checks if both are same if (answer) cout << "Beginner and Beginner are treated similarly in the container\n" ; else cout << "Beginner and Beginner are treated dissimilarly in the container\n" ; return 0; } |
Beginner and Beginner are treated dissimilarly in the container
Time Complexity-O(1)
Program 2:
CPP
// CPP program to illustrate the // unordered_multiset::key_eq() function #include <iostream> #include <string> #include <unordered_set> using namespace std; int main() { unordered_multiset< int > sampleSet; bool answer = sampleSet.key_eq()(100, 200); // check if (answer) cout << "100 and 200 are treated similarly in the container\n" ; else cout << "100 and 200 are treated dissimilarly in the container\n" ; answer = sampleSet.key_eq()(100, 100); if (answer) cout << "100 and 100 are treated similarly in the container\n" ; else cout << "100 and 100 are treated dissimilarly in the container\n" ; return 0; } |
100 and 200 are treated dissimilarly in the container 100 and 100 are treated similarly in the container
Time Complexity: O(1)
Contact Us