Synopsis
Declared in <mp-units/framework/unit.h>
template<
Unit U1,
Unit U2,
Unit... Rest>
struct common_unit final
: ::_base_type_
Description
While adding two quantities of different units we can often identify which of those unit should be used to prevent data truncation. For example, adding 1 m + 1
mm` will end up in a quantity expressed in millimeters. However, for some cases this is not possible. Choosing any of the units from the arguments of the addition would result in a data truncation. For example, a common unit for 1 km + 1
mi` is [8/125] m
. Instead of returning such a complex unit type the library will return a common_unit<mi, km>
. This type is convertible to both mi
and km
without risking data truncation, but is not equal to any of them.
NOTE
User should not instantiate this type! It is not exported from the C++ module. The library will instantiate this type automatically based on the unit arithmetic equation provided by the user.