diff --git a/au/code/au/quantity.hh b/au/code/au/quantity.hh index 3cdf2b9..cb9c786 100644 --- a/au/code/au/quantity.hh +++ b/au/code/au/quantity.hh @@ -534,6 +534,20 @@ constexpr auto operator%(Quantity q1, Quantity q2) { return make_quantity(q1.in(U{}) % q2.in(U{})); } +// Callsite-readable way to convert a `Quantity` to a raw number. +// +// Only works for dimensionless `Quantities`; will return a compile-time error otherwise. +// +// Identity for non-`Quantity` types. +template +constexpr R as_raw_number(Quantity q) { + return q.as(UnitProductT<>{}); +} +template +constexpr T as_raw_number(T x) { + return x; +} + // Type trait to detect whether two Quantity types are equivalent. // // In this library, Quantity types are "equivalent" exactly when they use the same Rep, and are diff --git a/au/code/au/quantity_test.cc b/au/code/au/quantity_test.cc index 74513b9..a4819a7 100644 --- a/au/code/au/quantity_test.cc +++ b/au/code/au/quantity_test.cc @@ -55,6 +55,12 @@ static constexpr QuantityMaker meters{}; static_assert(are_units_quantity_equivalent(Centi{} * mag<254>(), Inches{} * mag<100>()), "Double-check this ad hoc definition of meters"); +struct Unos : decltype(UnitProductT<>{}) {}; +constexpr auto unos = QuantityMaker{}; + +struct Percent : decltype(Unos{} / mag<100>()) {}; +constexpr auto percent = QuantityMaker{}; + struct Hours : UnitImpl