I wanted to put in a plug for my employer's open-sourced C++ units framework, called Au: <a href="https://github.com/aurora-opensource/au">https://github.com/aurora-opensource/au</a><p>The library incorporates dimensional units into the C++ type system with an emphasis on correctness (including considerations for overflow, rounding, loss of precision, etc) and minimal runtime overhead.<p>As a very simple example of what using this library could look like, here is a tiny code snippet taken from one of the tutorials:<p><pre><code> constexpr double speed_mph = 65.0;
constexpr double speed_mps = (miles / hour)(speed_mph).in(meters / second);
</code></pre>
In a larger program, of course, the whole point is to avoid using naked "doubles" (or floats or ints, etc) at all, and instead use the library's "Quantity" types, which encode information about their units. Conversions are done automatically, and incompatible operations become compile-time errors.<p><pre><code> const auto time = hours(1.0)
const auto distance = miles(65.0)
const auto average_speed = distance/time;
</code></pre>
The tutorials are a nice way to be introduced to the library:
<a href="https://aurora-opensource.github.io/au/tutorial/" rel="nofollow noreferrer">https://aurora-opensource.github.io/au/tutorial/</a><p>From a user's point of view (I am a physicist by training), I find the library wonderfully unobtrusive and "natural" to use.