3 ms·
I wanted to put in a plug for my employer's open-sourced C++ units framework, called Au: https://github.com/aurora-opensource/au https://github.com/aurora-opens
by tobinfricke 3y ago
I wanted to put in a plug for my employer's open-sourced C++ units framework, called Au: https://github.com/aurora-opensource/au https://github.com/aurora-opensource/au
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.
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:
constexpr double speed_mph = 65.0;
constexpr double speed_mps = (miles / hour)(speed_mph).in(meters / second);
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.
const auto time = hours(1.0)
const auto distance = miles(65.0)
const auto average_speed = distance/time;
The tutorials are a nice way to be introduced to the library:
https://aurora-opensource.github.io/au/tutorial/ https://aurora-opensource.github.io/au/tutorial/
From a user's point of view (I am a physicist by training), I find the library wonderfully unobtrusive and "natural" to use.
- V1ndaar 3y agoNice, that looks very interesting. I'll remember it in case I need to do some C++ work in the future again! I developed a similar library for Nim, `unchained` [0]. Thanks to Nim's extensive macro system it's a pleasure to use (from a short look at the `au`'s docs my biased opinion is it beats `au` on usability :) ). [0]: https://github.com/SciNim/Unchained https://github.com/SciNim/Unchained