Opposite to sequence containers, associative containers in C++ STL store elements following a specific ordering based on the element's key, or in an unordered fashion that uses hash codes for organizing elements. Unlike sequence containers, they provide faster element search, insertion, and deletion operations, independent of the container's size.
The associative containers include
- std::set
- std::multiset
- std::map
- std::multimap
And the unordered varieties
- std::unordered_set
- std::unordered_multiset
- std::unordered_map
- std::unordered_multimap
For example, std::map is a sorted associative array that is accessed by keys, whereas std::unordered_map uses hashing to allow for constant time complexity on average for addition, searching, and deletion operations.