The Smart Pointers I Wish I Had
summary
Shows a concrete fix: convert non-owning raw pointers to a typed non-owning pointer (uses the C++20 observer_ptr idea, implemented a custom borrowed_ref/borrowed_ptr), removes .get from internal smart pointers, and tightens APIs so ownership is explicit. A latent bug that takes "two months" to find motivates the change; a codebase migration takes weeks to roll back and rework when performance regresses but ultimately prevents those lifetime races. Claims roughly "70% solved" by observer_ptr ergonomics and reports multi-year, incremental adoption across a million-line codebase.
AI-written summary · about
chapters (24)
- 0:00Intro
- 0:47My Domain
- 3:02Click-Bait Title
- 4:42Definitions
- 5:53Using Tools to Detect Lifetime Issues
- 7:11Guideline 1: No Owning Raw Pointers
- 9:19Too Easy to Type the Wrong Thing?
- 12:10Thesis 2
- 12:28Guideline 2: No Non-Owning Raw Pointers
- 13:18Thesis 3
- 13:51observer_ptr in Brief
- 17:50get() considered harmful?
- 21:27Implicit Construction?
- 24:47Fixing(?) Raw References
- 26:51Non-Local Reasoning
- 28:28Async Changes Understanding of Lifetime
- 31:24Apply Google's Rules...
- 32:27Apply Smart Pointer Guidelines...
- 33:48Non-Owning Smart Pointers
- 40:13Guideline 3
- 42:29Migrating Code
- 46:29Appendix A
- 46:45Multi-threaded races
- 47:26Appendix B








