FREE COURSE / REAL PRACTICE
Containers & views (C++)
Choose C++ containers and views by storage, lookup, ordering, ownership and invalidation contracts.
What you’ll work toward
Explain container tradeoffs and test boundary cases instead of choosing a data structure by familiarity alone.
Read an explanation, inspect the diagrams and work through the available checks, debugging exercises and builds. Feedback and prerequisite links guide the next step.
Before you start
This course builds on these skills:
Individual lessons can add prerequisites. The course map shows your actual readiness.
A look inside the first lesson
std::vector, std::span and std::string_view
#include <print>
#include <string>
#include <vector>
int main() {
std::vector<int> a(3, 1); // (count, value): three 1s
std::vector<int> b{3, 1}; // initializer list: the two elements 3 and 1
std::println("{} {}", a, b);
// If the braced values can't form an initializer_list<T>, braces fall back
// to the other constructors: 3 isn't a std::string, so this is (count, value).
std::vector<std::string> c{3, "x"};
std::println("{}", c);
}Your course outline
Follow the lessons in curriculum order. Open a unit to preview the ideas you’ll work with.
Owning things
- LESSON 02.01
Move semantics and value categories
Know which expressions can be moved from, write correct noexcept move operations, and know when the compiler elides copies for you.
Open lesson - LESSON 02.02
Dynamic array (your own vector)
Separate raw storage from live objects, grow geometrically for amortized O(1) push_back, and keep ownership, aliasing and exceptions straight.
Open lesson - LESSON 02.03
Stacks, queues and ring buffers
LIFO and FIFO, the standard adaptors, and a growable ring buffer with O(1) push and pop at both ends of its life.
Open lesson - LESSON 02.04
Hash maps and sets in practice
Use std::unordered_map and unordered_set for O(1)-average counting, grouping and lookup — and know their traps: operator[] inserts, order is unspecified, the hash decides your complexity.
Open lesson
Generic code
- LESSON 03.01
Iterators and ranges basics
Know what each iterator category promises, make your own container work with std::ranges, and use sentinels, projections and simple views.
Open lesson - LESSON 03.02
Linked lists
Node-based sequences: sentinels that delete edge cases, O(1) splicing, iterative reversal and teardown, fast/slow pointers — and why they lose to vectors on modern hardware.
Open lesson
Compile time and trees
- LESSON 05.01
Flat containers: flat_map and inplace_vector
Sorted-vector maps for read-mostly data, and fixed-capacity vectors that never allocate — when they beat node-based and heap-based containers, and what they cost.
Open lesson - LESSON 05.02
Binary trees and binary search trees
Traverse trees in every order, keep the BST invariant through insert and erase, and never let a degenerate tree overflow your stack.
Open lesson
Sum types, contracts, graphs
Pipelines and memory
- LESSON 07.01
Ranges: views and pipelines
Compose lazy views with |, materialise with ranges::to, fold, generate with std::generator, and know where views dangle or cache.
Open lesson - LESSON 07.02
Allocators and std::pmr
Control where containers get their memory: the allocator model, propagation traits, polymorphic memory resources, arenas, and the lifetime rules that keep them safe.
Open lesson - LESSON 07.03
Fixed-capacity containers: no hidden allocations
Game- and embedded-style containers in the spirit of EASTL: inline storage with an optional heap overflow, small-buffer optimisation, fixed node pools — and why a frame budget bans surprise allocations.
Open lesson
Standard containers: contracts, bits & duplicate keys
- LESSON 08.01
Standard containers: identity, transfer & invalidation
Apply list splice, forward_list erasure, map node handles and borrowed array views; choose storage by ownership and stability guarantees.
Open lesson - LESSON 08.02
Packed booleans: vector<bool>, proxies & bitset
Distinguish bit proxies from boolean values, use fixed-width bit operations beyond 64 bits, and preserve snapshots, bounds and subset-sum semantics.
Open lesson - LESSON 08.03
Duplicate keys: ordered, hashed & flat containers
Use multimap/multiset and unordered multi variants, plus flat_set/flat_multiset/flat_multimap; preserve multiplicity, deterministic results and sorted invariants.
Open lesson
Shaped views & stable block storage
- LESSON 09.01
mdspan: shape, strides & borrowed multidimensional data
Use actual C++23 mdspan with right, left and padded layouts; validate backing spans and overflow, distinguish logical size from storage, and transpose safely.
Open lesson - LESSON 09.02
hive storage: stable entities with the reference implementation
Practice stable insertion and erasure using pinned plf::hive, with a consistent id index and lifetime checks. Native std::hive remains unavailable here.
Open lesson