Search⌘ K

Introduction

Explore the fundamentals of C++ associative containers, including std::set, std::map, and their unordered counterparts. Understand how keys relate to values, the difference between sorted and unsorted keys, and how these affect insertion, deletion, and access performance.

We'll cover the following...

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
...