What is the difference between set::key_comp vs set::value_comp in C++? Going to cplusplus.com page there is no significant difference. Furthermore on set::key_comp & related set::value_comp pages last sentence is "(...) key_comp and its sibling member function value_comp are equivalent."
Examples are almost the same:
http://www.cplusplus.com/reference/set/set/key_comp/
http://www.cplusplus.com/reference/set/set/value_comp/
key_comp
defines the order of the keys in a container.
value_comp
defines the order of the values in a container.
In a std::set
where, essentially, the values are the keys, the two are indeed exactly equivalent. But that's not true in all containers, e.g. std::map
, or, in general, in a container that you might build yourself that follows the conventions of the C++ Standard Library Containers.
Note also that http://en.cppreference.com/w/ is a superior reference for C++. It pretty much proxies the standards.
These are identical, both must be made available by any implementation because std::set
must meet the requirement of Associative Container.
This allows you to write generic code that works with any Associative Container (std::set
, std::map
, std::multiset
, std::multimap
in the standard library).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With