Extreme Type Safety with Opaque Typedefs
summary
Library implements opaque typedef library semantics by wrapping existing types via inheritance to create distinct address/offset types, letting code overload and delete operators. It is ~1400 lines, licensed BSD 3-clause, produces zero runtime overhead, and catches real bugs (found a wrong-width integer assignment at compile time). Operators are customizable so address+offset returns address while address-address yields offset. Works on GCC and clang; Visual Studio 2015 had issues.
AI-written summary · about
chapters (11)
- 0:00Intro
- 0:13Motivating Example
- 1:09Common Mitigations
- 1:52Typedef - good, not great
- 3:32Basic Opaque Typedef
- 4:16That's pretty good!
- 5:09A foundation for more...
- 6:22Specifying binary operators
- 7:44Straightforward extensions
- 9:36I can haz code?
- 10:54What I want in exchange
related talks
01h 13mType safe C++ – LOL! :-)
01h 02mFancy Pointers for Fun and Profit
59mStrongly Typed Containers
57mFun with Type Erasure: Implementing a Value Wrapper for Polymorphic Types
50mType safe C++? LOL!
55mBreaking Dependencies: Type Erasure - The Implementation Details
01h 22mThese 10 tricks that only library implementors know!
58mHow to Build Cpp Interfaces That Are Hard to Use Incorrectly
