Using Units, Qantities, and Dimensions in C++14

By Peter Sommerlad

The zero-cost abstraction capabilities have the potential to make code computing physical properties much safer by incorporating not only a numerical value, but also its physical dimension into the type system. Instead of providing a comment, like, "this number represents a velocity in km per hour" one can define a variable of dimension velocity and provide units like "meter per second", "kilometer per hour", or "nautical knots" to convert numeric values into a velocity quantity.

Boost::Units as a library has been a long time around but didn’t get the appreciation it might deserve. However, its design is "ancient" and more modern C++ style is asked for. Martin Moene provides a C++11 compile-time units library based on previous design by Michael S. Kenniston. This talk will motivate using units, quantities and dimensions and provides a short C++14 DIY guideline and demonstrates the uses of Boost::Units and Martin Moene’s PhysUnits C++11 (or a slightly modernized C++14 version of it).

After this talk, you will stop using plain double or float for representing physical units and switch to use a units library. My plan is, to suggest standardizing a units library for a future ISO C++ standard, your help is appreciated.