If you are looking for compile time and prevention of unit errors in equations for dimensional analysis one of these libraries might work for you.
- boost units -Zero-overhead dimensional analysis and unit/quantity manipulation and conversion in C++
- Units -A compile-time, header-only, dimensional analysis library built on with no dependencies.
C++14
- Units -Another compile time library
- PhysUnits-CT A C++ library for compile-time dimensional analysis and unit/quantity manipulation and conversion.
- PhysUnits-RT -A C++ library for run-time dimensional analysis and unit/quantity manipulation and conversion.
- Libunits -The ultimate shared library to do calculations(!) and conversions with any units! Includes all SI and pseudo SI units and thousands of US, Imperial and other units.
- unitscpp -A lightweight C++ library for physical calculation with units.
- mpusz/units -A compile-time enabled Modern C++ library that provides compile-time dimensional analysis and unit/quantity manipulation.
- bernedom/SI -A header only C++ library that provides type safety and user defined literals for handling physical values defined in the International System of Units
These libraries will work well if the number of units being dealt with is known at compile time. Many also produce zero overhead operations and checking. Therefore in situations where this is possible other libraries are a preferred alternative.
Reasons to choose this units library over another option
- Conversions to and from regular strings are required
- The number of units in use is large
- A specific single unit or measurement type is required to handle many different kinds of units or measurements
- Uncertainties are needed to be included with the measurements
- Working with per unit values
- Dealing with commodities in addition to regular units. i.e. differentiate between a gallon of water and a gallon of gasoline
- Dealing with equation type units
- Complete C++ type safety is NOT a critical design requirement.
- Support is needed for some funky custom unit with bizarre base units.
Reasons to choose something else
- Type safety and dimensional analysis IS a design requirement
- Performance is absolutely critical (many other libraries are zero runtime overhead)
- You are only working with a small number of known units
- You cannot use C++11 yet.
- You need to operate on arbitrary or general fractional powers of base units
- You need support for arbitrary datum shifts in the unit library