Implementing static_vector: How Hard Could it Be?
summary
Stack-allocated static_vector claims std::vector semantics but with inline storage, and the talk drills into real tradeoffs: a size optimization that can be 18 vs 24 bytes (33% increase), why a stack allocator breaks value semantics, why raw byte storage needs alignas and an uninitialized array wrapper, the memcpy-null-pointer issue that forces a custom memcpy, how constexpr interacts with construct_at, and why relocation / trivially relocatable support and non-constant-time swap force API and standard changes to make a production-quality static_vector.
AI-written summary · about
chapters (17)
- 0:00Start
- 0:26What Is Static Vector
- 3:40Parts of the Interface of Static Vector
- 5:18Size Optimization
- 6:29Storage of the Data
- 7:16Breaks Value Semantics
- 12:02Uninitialized Array
- 16:26Why Do I Have no Unique Address on the Member Variable
- 17:55Implicit Lifetime Types
- 27:03Proposal for C plus 23 To Make It Easier To Write Range Adapters
- 38:51Move Constructor
- 39:43Conditionally Trivial Special Member Functions
- 41:10Trivial Relocation
- 44:25Relocating Unique Pointer
- 49:23What Happens if Move Throws an Exception
- 50:28Swap
- 50:57Swap Static Vectors
related talks
57mHow to Design a Slimmer Vector of Variants in C++
55mC++ Cache Friendly Data + Functional + Ranges = ❤️
46mWords of Wisdom
06mLightning Talk: Cute Approach for Polymorphism in C++
05mSimple Solutions for High Performance: StaticFlatMap
01h 00mMissing (and future?) C++ range concepts
01h 02mBreaking Dependencies - The Visitor Design Pattern in Cpp
01h 07mDependency Injection Patterns: Efficiency and Usability
