Back to Basics: Almost Always Vector
Talkat CppCon 2024 · on Monday, 2024-09-16· at 14:00· Maple 3/4/5, 6700 North Gaylord Rockies Boulevard·
summary
Argues that std::vector is the right default for most C++ work and demonstrates why with concrete code: push_back and reallocation behavior, capacity vs size, reserve to avoid reallocations, iterator invalidation rules and pointer-like arithmetic, use of data() for C interop and at() throwing, lambdas and find_if, and a real workload (nlohmann JSON → vector of credit‑card records) that runs 10k and 100k items (100k costs about 2× the time). Slides and runnable code live on the GitHub link.
AI-written summary · about
chapters (14)
- 0:00Welcome to Almost Always Vector
- 1:07Why C++ devs avoid std::vector
- 7:30Static arrays limitations
- 10:04std::vector basics and creation
- 17:52Stack vs heap memory
- 23:25Vector size vs capacity
- 27:14Memory allocation with reserve
- 31:49Iterators in std::vector
- 37:02Iterator invalidation pitfalls
- 41:14STL algorithms with std::vector
- 46:14Credit card data example
- 51:34std::vector vs other containers
- 54:24Why std::vector is default
- 56:31Q&A
related talks
01h 04mBack to Basics: Move Semantics
48mBack to Basics: Cpp Value Semantics
01h 02mBack to Basics: Iterators in C++
58mUnderstanding and Mastering C++'s Complexity
01h 40mBack to the Basics! Essentials of Modern C++ Style
01h 02mC++20 - My Favorite Code Examples
01h 00mSTL Features And Implementation Techniques
01h 16mC++ Today: The beast is back
