How to Hold a T
summary
Containers separate allocation and construction: T is the wrong type to hold a T, so use an unrelated storage type (char buffer or a union) and manually control lifetime with placement new and an explicit destructor. Practical claim: union storage gives correct size/alignment and supports multi-dimensional layouts, but non-trivial members require a user-written ctor/dtor and the container must handle exception safety. Warning: aligned_storage is UB and is fragile; real std::vector/optional implementations use these techniques and they work.
AI-written summary · about
chapters (5)
related talks
01h 04mHow to Write a Custom Allocator
34mAllocator-Aware C++ Type Design
59mStrongly Typed Containers
05mPlacement New
01h 31mNew (& Old) C++ Standard Library Containers - How to Choose the Right Container in C++26 and Beyond
41m“Avoiding Disasters with Strongly Typed C++”
01h 33mSafe and Sane C++ Types
05mThe Object Upside Down
