Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Every standard container, and when to pick it

array, vector, string, deque, list, map, set and their unordered twins, with the one question that picks between them.

Decide by what the program does to the data most often.

  1. Looked up by a key, not by position? Key with a value → a map. Key alone → a set. Need sorted order, or the same output on every platform → std::map / std::set. Order never matters and speed does → the unordered_ versions.
  2. Otherwise it's a sequence. Size fixed when the program is built → std::array. Adding or removing at the front as well as the back → std::deque. Inserting and erasing in the middle at iterators you hold, where other iterators must stay valid → std::list.
  3. Everything else → std::vector. It's contiguous, so walking it is fastest, and it works with std::span and C APIs.

Text is a std::string. Whatever you pick, check what its changes do to iterators you're holding.

Sequences

Why a full vector reallocates and moves every element into a bigger block.

Looked up by key

Before you rely on it

How they work inside