Hand-Rolling mini STL: A Container Library in Practice
We hand-roll a teaching-oriented mini container library of our own (namespace tamcpp::ministl): starting from a raw buffer that "manages capacity, not objects", we work our way up to an LRU cache. Each time we finish a piece, we hold it up against a real industrial implementation as a mirror — the dynamic array against std::vector and Chromium's vector_buffer, the classic linked list against libstdc++'s stl_list, hashing against absl's swiss table, and the ring buffer, intrusive containers, and LRU cache against Chromium's base/containers. Whichever mirror we borrow, its error handling comes along: the std mirror throws exceptions, the Chromium mirror crashes on the spot.
Prerequisites: you have read the conceptual layer of the vol3 containers volume, you can read template specializations and variadic templates, and ideally you have dealt with placement new at least once. The companion code lives in code/volumn_codes/vol8-labs/ministl/ and advances stage by stage in separate directories (currently stage1_rawbuf_vector/: RawBuffer and Vector); every article's output can be reproduced verbatim in there.
Prerequisites
Hands-On Series
- 01 RawBuffer: capacity, not objects — decoupling memory from object lifetimes, with
placement newand explicit destruction taking the stage in pairs - 02 Vector: growth and relocation — a minimal two-member layout, the doubling strategy, and amortized analysis
- 03 Vector: the Rule of Five, exception safety, and concepts — copy-and-swap, move_if_noexcept, and a retrospective on a real bug
We keep pushing this series forward module by module. Upcoming articles will revolve around the ring buffer, linked lists (singly linked, doubly linked, intrusive), ordered and hash maps, heaps, and the LRU cache; each one gets its link added here as soon as it lands.
Related Content
- the vol8 algorithms subdomain: sorting, searching, and the rest of "the algorithms half" belong over there; hand-written container implementations belong over here
- the vol3 containers volume: the conceptual layer of std containers, the prerequisite for this series
- the flat_map series: a complete deep dive into sorted-vector containers; the later FlatMap assembly article will stand directly on its shoulders
- the vol4 mini-STL algorithm library: over there it's concepts practice; over here it's systematic hand-rolling