multimap key_comp in C++ STL Last Updated : 12 Nov, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report This is the part of Standard Template Library(STL) of C++. To use this STL, use Namespace: std and include “map” header file in the program. It returns the function object or comparison object or ordering delegate that compares the keys, which is a copy of this container's constructor argument. It is a function pointer or an object that takes two arguments of the same type as the element keys and determines the order of the elements in the container. Syntax: key_compare key_comp(); Here key_compare is the type of the comparison object, which is associated to the container. Parameters: It does not accept any parameter. Returns: It returns the key comparison function object or ordering delegate, which is defined in multimap as an alias of its third template parameter. Below is an example of multimap::key_comp: CPP // c++ program to show // the use of multimap::key_comp #include <iostream> #include <map> using namespace std; // Driver code int main() { multimap<char, int> m1; //'comp' works as a variable multimap<char, int>::key_compare comp = m1.key_comp(); // set the values of the pairs m1.insert(make_pair('a', 10)); m1.insert(make_pair('b', 20)); m1.insert(make_pair('b', 30)); m1.insert(make_pair('c', 40)); // key value of last element char h = m1.rbegin()->first; multimap<char, int>::iterator i = m1.begin(); do { cout << (*i).first << " = " << (*i).second << '\n'; } while (comp((*i++).first, h)); return 0; } Output: a = 10 b = 20 b = 30 c = 40 Comment More infoAdvertise with us Next Article multimap::emplace() in C++ STL S SoumikMondal Follow Improve Article Tags : Technical Scripter C++ STL cpp-multimap cpp-multimap-functions +1 More Practice Tags : CPPSTL Similar Reads multimap key_comp() in C++ STL The std::multimap::key_comp() is an inbuilt function in C++ STL which returns a copy of the comparison object used by the container.By default, this is a less object, which returns the same as operator â<'.It is a function pointer or a function object which takes two arguments of the same ty 2 min read multimap::count() in C++ STL The multimap::count is a built-in function in C++ STL which returns the number of times a key is present in the multimap container. Syntax: multimap_name.count(key) Parameters: The function accepts one mandatory parameter key which specifies the key whose count in multimap container is to be returne 1 min read set::key_comp() in C++ STL set::key_comp() is an inbuilt function in C++ STL which returns a copy of the comparison object used by the container. By default, this is a less object, which returns the same as operator '. This object determines the order of the elements in the container. It is a function pointer or a function ob 2 min read Multimap in C++ STL In C++, multimap is an associative container similar to map, but it can have multiple elements with same keys. It stores all the elements in increasing order based on their keys by default but can be changed if required. It provides fast insertion, deletion and search on this sorted data.Example:CPP 8 min read multimap::emplace() in C++ STL The multimap::emplace() is a built-in function in C++ STL which inserts the key and its element in the multimap container. It effectively increases the container size by one as multimap is the container that stores multiple keys with same values. Syntax: multimap_name.emplace(key, element) Parameter 1 min read multimap insert() in C++ STL The multimap::insert is a built-in function in C++ STL that is used to insert elements in the multimap container. Syntax: iterator multimap_name.insert({key, element}) Parameters: The function accepts a pair that consists of a key and element which is to be inserted into the multimap container. Retu 2 min read Like