Introduction
After sequential containers, let's enter the world of associative containers and learn about the principle of key-value pairs.
C++ has eight different associative containers. Four of them are associative containers with sorted keys: std::set
, std::map
, std::multiset
, and std::multimap
. The other four are associative containers with unsorted keys: std::unordered_set
, std::unordered_map
, std::unordered_multiset
, and std::unordered_multimap
. The associative containers are special containers. That means they support all of the operations described in the chapter containers in general.
Overview
All eight ordered and unordered containers have one thing in common: they associate a key with a value. We can use the key to get the value. To classify the associative containers, three simple questions need to be answered:
- Are the keys sorted?
- Does the key have an associated value?
- Can a key appear more than