After reading this link: https://en.cppreference.com/w/cpp/container/set, I just found that there were two defined types: key_type and value_type in the class std::set. It seems that they are exactly the same thing.
Well, this may be a stupid question but I still want to ask why. Isn't one enough? Why are there two types?
All the stl containers have value_type, and all the associative containers (including std::set, std::map, std::multiset, std::multimap) and unordered associative containers (including std::unordered_set, std::unordered_map, std::unordered_multiset, std::unordered_multimap) have key_type, that means you can perform some general processing (with templates especially) on these containers with the member types.
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