Programming for Warm Days: Avoiding Dangerous Conversions
summary
Live codes a small C++ library that replaces raw doubles with a templated strong type for units, using temperature traits and a single neutral unit so conversions route through Celsius. Implements constexpr temperature_cast, user‑defined literals (_C/_F/_K), conversion constructors and a concepts‑based close‑enough comparator. Default values use freezing points per unit, performance aims to match macros via inlining, and the demo compiles and runs after fixing overload ambiguities — conversions and comparisons work as intended.
AI-written summary · about
chapters (11)
- 0:00Introduction and context
- 4:26The problem with raw types
- 7:07Designing the traits system
- 10:32Implementing the conversion
- 16:13Building the temperature class
- 21:55Conversion constructor
- 28:21User-defined literals
- 34:42Implementing comparisons
- 42:11Handling numeric precision
- 49:20Finalizing the class
- 52:04Safety and concluding remarks
related talks
51mThe C++ Type System is your Friend
01h 36mEmbracing User-Defined Literals Safely
01h 37mRethinking the Way We Do Templates in C++ even more
01h 30mRethinking the Way We Do Templates in C++
01h 31mImplementing Physical Units Library for C++
01h 30mEnhancing Safety in C++ Code With Modern C++ Quantities and Units Library
01h 10mThe C++ Type System Is Your Friend
01h 03mHow to Improve the Safety of C++ Code With a Quantities & Units Library
