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.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.