mp_units::common_unit

Measurement unit for an accumulation of two quantities of different units

Synopsis

Declared in <mp-units/framework/unit_definitions.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.

Base Classes

NameDescription
::_base_type_

Type Aliases

NameDescription
_base_type_ Exposition-only alias naming this specialization's base type.

Static Data Members

NameDescription
_common_unit_ The scaled unit shared by U1, U2, and Rest

Non-Member Functions

NameDescription
get_common_unitComputes the common unit of a common_unit compound and a single new unit
get_common_unitComputes the common unit of two common_unit compounds by merging their unit lists