A named unit
Synopsis
Declared in <mp‐units/framework/unit.h>
template<
symbol_text Symbol,
auto...>
struct named_unit;
Derived Classes
Name |
Description |
Description
Defines a unit with a special name. It may be used to provide a base unit in the system of units (e.g. metre
) or a name assigned to another scaled or derived unit (e.g. hour
, joule
). Most of the named units may be composed with a prefix to create a prefixed_unit
.
For example:
{.cpp}
inline constexpr struct second final : named_unit<"s", kind_of<time>> {} second;
inline constexpr struct metre final : named_unit<"m", kind_of<length> {} metre;
inline constexpr struct hertz final : named_unit<"Hz", inverse(second), kind_of<frequency>> {} hertz;
inline constexpr struct newton final : named_unit<"N", kilogram * metre / square(second)> {} newton;
inline constexpr struct degree_Celsius final : named_unit<{u8"℃", "`C"}, kelvin, zeroth_degree_Celsius> {}
degree_Celsius; inline constexpr struct minute final : named_unit<"min", mag<60> * second> {} minute;
Note
|
A common convention in this library is to assign the same name for a type and an object of this type. Besides defining them user never works with the unit types in the source code. All operations are done on the objects. Contrarily, the unit types are the only one visible in the compilation errors. Having them of the same names improves user experience and somehow blurs those separate domains. |
Template Parameters
Name |
Description |
Symbol |
a short text representation of the unit |
Created with MrDocs