Safe

last modified: October 23, 2025

Units of Measurements for Safe C++ Variables

Posted on 2019-07-11— C++, Improve your Code, Learn

I show how I avoid unit mistakes in C++ by creating a templated Duration type and user-defined literals like 100_ms. I explain declaring Seconds/Milliseconds/Nanoseconds, adding conversions, and how the compiler catches unit mismatches with no runtime cost. Read the full article for code examples and the GitHub repo.

Read this post