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 object which takes two arguments of the same type as the container elements and returns true if the first argument is considered to go before the second in the strict weak ordering it defines or false otherwise. Two elements of a set are considered equivalent if key_comp returns false reflexively (i.e., no matter the order in which the elements are passed as arguments).
Parameters: This function does not accept any parameter.
Return value: The function returns a copy of the comparison object used by the container.
Program to demonstrate the above function:
Set a has the numbers: 0 1 2 3 4 5 6 7 8 9
- Different ways to use Const with Reference to a Pointer in C++
- std::to_address in C++ with Examples
- Program to create Custom Vector Class in C++
- std::is_trivially_copy_constructible in C/C++
- Difference between Python and C++
- tgamma() method in C/C++ with Examples
- boost::type_traits::is_array Template in C++
- boost is_pointer template in C++
- Stack of Pair in C++ STL with Examples
- Modulo Operator (%) in C/C++ with Examples
- fpclassify() method in C/C++ with Examples
- Operator Overloading '<<' and '>>' operator in a linked list class
- Set of Vectors in C++ STL with Examples
- How to find the Entry with largest Value in a C++ Map
- Visibility Modes in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.