[#mp_units-common_unit] = xref:mp_units.adoc[mp_units]::common_unit :relfileprefix: ../ :mrdocs: Measurement unit for an accumulation of two quantities of different units == Synopsis Declared in `<mp‐units/framework/unit.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< xref:mp_units/Unit.adoc[Unit] U1, xref:mp_units/Unit.adoc[Unit] U2, xref:mp_units/Unit.adoc[Unit]... Rest> struct common_unit final : ::_base_type_ ---- == Base Classes [cols=2] |=== | Name | Description | `::_base_type_` | |=== == Types [cols=1] |=== | Name | xref:mp_units/common_unit/_base_type_.adoc[`_base_type_`] |=== == Static Data Members [cols=1] |=== | Name | xref:mp_units/common_unit/_common_unit_.adoc[`_common_unit_`] |=== == 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. ==== [.small]#Created with https://www.mrdocs.com[MrDocs]#