The Curiously Recurring Pattern of Coupled Types
summary
Identifies a recurring type pattern as affine spaces and shows it in raw C pointers, STL iterators, std::chrono time_point/duration and 2D/3D positions, arguing that subtracting points yields vectors while adding points is meaningless. Implements a small C++17 library (demoed in Compiler Explorer) and C++20 concepts to enforce point vs vector types, uses a window-size example and std::midpoint to show compile-time errors instead of runtime bugs, notes zero-cost (even register-favorable) codegen, and explains how this prevents mistakes like mixing clocks or units.
AI-written summary · about
chapters (13)
- 0:00Introduction to affine spaces
- 14:19API design principles
- 15:36Real-world examples
- 15:59Chrono library analysis
- 18:15Iterators and containers
- 24:19Mars climate orbiter case
- 25:39GUI API design case study
- 26:23Library implementation
- 28:08Compiler explorer demo
- 28:44Performance and assembly
- 32:35C++20 concepts modeling
- 34:03Intermission
- 35:32Conclusion and Q&A
related talks
53mProduct Types for C++2x
01h 02mC++20 - My Favorite Code Examples
49mA Journey Into Non-Virtual Polymorphism in C++
01h 00mTemplate Metaprogramming: Type Traits (part 1 of 2)
53mRegular Types and why do I care?
01h 03mWriting sustainable software. The how and the what!
01h 37mExtending and Simplifying C++: Thoughts on Pattern Matching using `is` and `as`
48mBack to Basics: Cpp Value Semantics
