The set::value_comp() is an inbuilt function in cpp that returns a copy of the comparison object used by the container. This object determines the order of the elements in the container. It is a function pointer or a function object that 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, and false otherwise. Two elements of a set are considered equivalent if value_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.
Below program illustrates the above function.
Set a has the numbers 0 1 2 3 4 5 6 7 8 9
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- set::begin() and set::end() in C++ STL
- set::rbegin() and set::rend() in C++ STL
- Count number of unique Triangles using STL | Set 1 (Using set)
- bitset set() function in C++ STL
- set upper_bound() function in C++ STL
- set insert() function in C++ STL
- set find() function in C++ STL
- set equal_range() function in C++ STL
- set max_size() function in C++ STL
- set emplace_hint() function in C++ STL
- set count() function in C++ STL
- set crbegin() and crend() function in C++ STL
- set cbegin() and cend() function in C++ STL
- set lower_bound() function in C++ STL
- Dijkstra’s shortest path algorithm using set in STL
- numeric header in C++ STL | Set 2 (adjacent_difference(), inner_product() and iota())
- Graph implementation using STL for competitive programming | Set 1 (DFS of Unweighted and Undirected)
- Graph implementation using STL for competitive programming | Set 2 (Weighted graph)
- Counting Inversions using Set in C++ STL
- Insertion and Deletion in STL Set C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.