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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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()("GEEKS", "geeks");
  
    // checks if both are same
    if (answer)
        cout << "GEEKS and geeks are treated similarly in the container\n";
    else
        cout << "GEEKS and geeks are treated dissimilarly in the container\n";
  
    return 0;
}

chevron_right


Output:

GEEKS and geeks are treated dissimilarly in the container

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

100 and 200 are treated dissimilarly in the container
100 and 100 are treated similarly in the container


My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.