How to Improve the Safety of C++ Code With a Quantities & Units Library
summary
A Modern C++ quantities library claims concrete safety: mp-units implements P2981 to make unit errors fail at compile time, catches truncation when converting integers, and encodes kinds so incompatible quantities (energy vs force) refuse to mix. Examples include a 31% historical miles error in Columbus’s data and references to mishaps like the Mars Climate Orbiter. Performance stays competitive with primitives — the generated code has same assembly as doubles — but MSVC required recent bug workarounds.
AI-written summary · about
chapters (39)
- 0:00Introduction to CBP
- 0:31Physical units in software
- 1:53Impact of software bugs
- 5:08C++ safety challenges
- 7:01Library design goals
- 9:23Applications of units
- 10:16Issues in legacy code
- 11:53Inconsistent interfaces
- 13:52Library features
- 15:31Library capabilities
- 17:00Compiler support
- 19:30Standardization efforts
- 21:15Units library demo
- 22:18Safety through errors
- 24:13Stronger interface design
- 27:37Debugging library errors
- 28:33Performance comparisons
- 30:03Generic interfaces
- 30:53Practical use cases
- 33:13Affine space support
- 34:09Automatic conversions
- 34:49Unit definition limits
- 36:24Defining new units
- 37:49International units
- 39:15Preventing data loss
- 40:34Value preserving casts
- 42:54Columbus case study
- 44:21Historical unit analysis
- 46:56Calculating historical errors
- 49:32Library complexity
- 50:25Chrono comparison
- 51:17Safe numerical access
- 52:42Modeling complex domains
- 53:32Quantity specification
- 54:48Composability
- 55:53Compile-time validation
- 56:51Mathematical operations
- 58:20ISO 80000 compliance
- 59:31Conclusion and Q&A
related talks
01h 30mEnhancing Safety in C++ Code With Modern C++ Quantities and Units Library
01h 02mA Physical Units Library For C++
01h 23mThe Power of C++ Templates With mp-units: Lessons Learned & a New Library Design
01h 08mA Physical Units Library For the Next C++
01h 40mUsing Units, Qantities, and Dimensions in C++14
01h 31mImplementing Physical Units Library for C++
51mThe C++ Type System is your Friend
01h 13mThe 10 Essential Features for the Future of C++ Libraries
