Skip to content
Related Articles
Open in App
Not now

Related Articles

unordered_multimap key_eq() function in C++ STL

Improve Article
Save Article
Like Article
  • Last Updated : 08 Aug, 2018
Improve Article
Save Article
Like Article

unordered_multimap::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_multimap 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_multimap_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_multimap.

Return Value: The function returns a boolean value.

Below programs illustrate the unordered_multimap::key_eq() function:

Program 1:




// CPP program to illustrate the
// unordered_multimap::key_eq() function
  
#include <iostream>
#include <string>
#include <unordered_map>
  
using namespace std;
  
int main()
{
  
    unordered_multimap<string, string> sample;
  
    bool answer = sample.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;
}

Output:

GEEKS and geeks are treated dissimilarly in the container

Program 2:




// CPP program to illustrate the
// unordered_multimap::key_eq() function
  
#include <iostream>
#include <string>
#include <unordered_map>
  
using namespace std;
  
int main()
{
  
    unordered_multimap<int, int> sample;
  
    bool answer = sample.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 = sample.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;
}

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
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!