I have a project for which I wrote a simple units library. I don't think I'd be able to write any physics-related project now without using it (or a similar library). My Quantity class has a set of 8 parameters (7 SI base units and a hack that allows conversion between Hz and radians) + additional Scale and Offset parameters. Scale allows representing units other than SI (like Nautical Miles), Offset is for units like Celsius, for which 0°C == 273.15 K.<p>I can do things like:<p><pre><code> si::Length length = 15_m + 12_nm; // _nm for Nautical Miles
si::Area area = 1_m * 1_km; // Equals to 1000_m2
si::Power power = 1_m / 1_sec / 1_sec; // Compilation error, 1_m/s² is not a si::Power
</code></pre>
I don't have every possible User-Defined Literal, of course, so I end up doing this for less common units:<p><pre><code> using SomeLocalTypeName = decltype(1_rpm / 1_V);
</code></pre>
Something to thing about, when designing such library:<p>* What is 0_degC + 1_degC? 1_degC or… 273.15_K + 274.15_K = 547.3_K = 274.15_degC? I forbid operations between units if any of them has Offset parameter different than 0. I'm not sure if this is the good solution, though.<p>* Nm (Newton-meters) is the same unit as Joules. ;-)