mp_units::derived_unit¶
Measurement unit for a derived quantity
Synopsis¶
Declared in <mp-units/framework/unit_definitions.h>
template</* implementation-defined */... Expr>
struct derived_unit final
Description¶
Derived units are defined as products of powers of the base units.
Instead of using a raw list of exponents this library decided to use expression template syntax to make types more digestable for the user. The positive exponents are ordered first and all negative exponents are put as a list into the per<...> class template. If a power of exponent is different than 1 the unit type is enclosed in power<Dim, Num, Den> class template. Otherwise, it is just put directly in the list without any wrapper. There is also one special case. In case all of the exponents are negative then the one being a coherent unit of a dimensionless quantity is put in the front to increase the readability.
For example:
static_assert(inverse(second) == derived_unit<struct one, per<struct second>>{});
static_assert(one / inverse(second) == second);
static_assert(one * second == second);
static_assert(metre * metre == derived_unit<power<struct metre, 2>>{});
static_assert(metre * second == derived_unit<struct metre, struct second>{});
static_assert(metre / second == derived_unit<struct metre, per<struct second>>{});
static_assert(metre / square(second) == derived_unit<struct metre, per<power<struct second, 2>>>{});
static_assert(watt / joule == derived_unit<struct watt, per<struct joule>>{});
Every unit in the library has its internal canonical representation being the list of exponents of named base units (with the exception of kilogram which is represented as gram here) and a scaling ratio represented with a magnitude.
Two units are deemed convertible if their canonical version has units of the same type. Two units are equivalent when they are convertible and their canonical versions have the same scaling ratios.
The above means that:
1/sandHzare both convertible and equalmandkmare convertible but not equalmandm²ane not convertible and not equal
Note
This also means that units likehertz and becquerel are also considered convertible and equal.
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.Non-Member Functions¶
| Name | Description |
|---|---|
cubic | |
equivalent | The former name of utility::equivalent |
get_quantity_spec | |
get_quantity_spec | |
get_unit | |
operator* | Multiplication operator |
operator* | Multiplication operator |
operator* | Multiplication operator |
operator* | Multiplication operator |
operator* | Multiplication operator |
operator/ | Division operator |
operator/ | Division operator |
operator/ | Division operator |
operator/ | Division operator |
operator/ | Division operator |
square |
Template Parameters¶
| Name | Description |
|---|---|
| Us | a parameter pack consisting tokens allowed in the unit specification (units, power<U, Num, Den>, per<...>) |