5 Quantities and units library [quantities]

5.4 Reference [qty.ref]

5.4.4 Unit [qty.unit]

5.4.4.2 Magnitude [qty.unit.mag]

5.4.4.2.1 General [qty.unit.mag.general]

Subclause [qty.unit.mag] specifies the components used to represent the numerical value (IEC 60050, 112-01-29) of a unit with support for powers (IEC 60050, 102-02-08) of real numbers (IEC 60050, 102-02-05).

5.4.4.2.2 Concepts [qty.unit.mag.concepts]

template<typename T> concept MagConstant = SymbolicConstant<T> && is-derived-from-specialization-of<T, mag_constant>(); template<typename T> concept UnitMagnitude = (is-specialization-of<T, unit-magnitude>()); template<typename T> concept MagArg = std::integral<T> || MagConstant<T>; // exposition only

5.4.4.2.3 Types [qty.unit.mag.types]

namespace mp_units { template<symbol_text Symbol, long double Value> requires(Value > 0) struct mag_constant { static constexpr auto symbol = Symbol; // exposition only static constexpr long double value = Value; // exposition only }; }
A specialization of mag_constant represents a real number (IEC 60050, 102-02-05).
Symbol is its symbol, and Value is (an approximation of) its value.
namespace mp_units { template<auto... Ms> struct unit-magnitude { // exposition only // [qty.unit.mag.ops], operations template<UnitMagnitude M> friend consteval UnitMagnitude auto operator*(unit-magnitude lhs, M rhs); friend consteval auto operator/(unit-magnitude lhs, UnitMagnitude auto rhs); template<UnitMagnitude Rhs> friend consteval bool operator==(unit-magnitude, Rhs); template<int Num, int Den = 1> friend consteval auto pow(unit-magnitude); // exposition only // [qty.unit.mag.utils], utilities friend consteval bool is-positive-integral-power(unit-magnitude); // exposition only template<auto... Ms2> friend consteval auto common-magnitude(unit-magnitude, // exposition only unit-magnitude<Ms2...>); }; }
A specialization of unit-magnitude represents the product of its template arguments.
For the purposes of specifying the implementation-defined limits, let the representation of the terms of unit-magnitude be the structure struct { ratio exp; base-type base; }; representing the number , where base-type is a model of MagArg.
  • There is a single term for each base-type.
  • exp.num is not expanded into base.
    [Note 1: 
    is not permitted.
    — end note]
  • exp.den can reduce the base.
    [Note 2: 
    is permitted.
    — end note]
  • If the result of an operation on std​::​intmax_t values is undefined, the behavior is implementation-defined.

5.4.4.2.4 Operations [qty.unit.mag.ops]

template<UnitMagnitude M> friend consteval UnitMagnitude auto operator*(unit-magnitude lhs, M rhs);
Returns:
  • If sizeof...(Ms) == 0 is true, returns rhs.
  • Otherwise, if std​::​is_same_v<M, unit-magnitude<>>, returns lhs.
  • Otherwise, returns an unspecified value equal to lhs ×rhs.
friend consteval auto operator/(unit-magnitude lhs, UnitMagnitude auto rhs);
Returns: lhs * pow<-1>(rhs).
template<UnitMagnitude Rhs> friend consteval bool operator==(unit-magnitude, Rhs);
Returns: std​::​is_same_v<unit-magnitude, Rhs>.
template<int Num, int Den = 1> friend consteval auto pow(unit-magnitude base); // exposition only
Returns:
  • If Num == 0 is true, returns unit-magnitude<>{}.
  • Otherwise, returns an unspecified value equal to .
template<MagArg auto V> constexpr UnitMagnitude auto mag = see below;
Constraints: V is greater than 0.
Effects: If MagConstant<decltype(V)> is satisfied, initializes mag with unit-magnitude<V>{}.
Otherwise, initializes mag with an unspecified value equal to V.
template<std::intmax_t N, std::intmax_t D> requires(N > 0) constexpr UnitMagnitude auto mag_ratio = see below;
Effects: Initializes mag_ratio with an unspecified value equal to .
template<MagArg auto Base, int Num, int Den = 1> constexpr UnitMagnitude auto mag_power = pow<Num, Den>(mag<Base>);
Constraints: Base is greater than 0.

5.4.4.2.5 Utilities [qty.unit.mag.utils]

friend consteval bool is-positive-integral-power(unit-magnitude x); // exposition only
Returns: false if x has a negative or rational exponent, and true otherwise.
template<auto... Ms2> friend consteval auto common-magnitude(unit-magnitude, unit-magnitude<Ms2...>); // exposition only
Returns: The largest magnitude C such that each input magnitude is expressible by only positive powers relative to C.