15template <
typename... RatiosT_>
17 using type = std::ratio<0>;
19template <
typename RatioT_,
typename... RatiosT_>
20struct RatioSum<RatioT_, RatiosT_...> {
21 using type = std::ratio_add<RatioT_,
typename RatioSum<RatiosT_...>::type>;
24using Gram = std::remove_cvref_t<
decltype(mp_units::si::gram)>;
27template <
typename UnitT_>
29 using type = std::ratio<0>;
32struct GramExponent<Gram> {
33 using type = std::ratio<1>;
35template <
int NumeratorV_,
int... DenominatorV_>
36struct GramExponent<mp_units::power<Gram, NumeratorV_, DenominatorV_...>> {
37 using type = std::ratio<NumeratorV_, DenominatorV_...>;
39template <
typename FactorT_,
typename... FactorsT_>
40struct GramExponent<mp_units::per<FactorT_, FactorsT_...>> {
42 std::ratio_subtract<std::ratio<0>,
43 typename RatioSum<typename GramExponent<FactorT_>::type,
typename GramExponent<FactorsT_>::type...>::type>;
45template <
typename... FactorsT_>
46struct GramExponent<mp_units::derived_unit<FactorsT_...>> {
47 using type =
typename RatioSum<typename GramExponent<FactorsT_>::type...>::type;
51template <
typename ReferenceT_>
52consteval auto coherentUnit(ReferenceT_ reference) {
53 using GramExponentT =
typename GramExponent<ReferenceT_>::type;
55 constexpr auto num = GramExponentT::num > 0 ? GramExponentT::num : -GramExponentT::num;
56 if constexpr (GramExponentT::num > 0) {
57 return mp_units::pow<num, GramExponentT::den>(mp_units::si::kilogram) *
58 (reference / mp_units::pow<num, GramExponentT::den>(mp_units::si::gram));
59 }
else if constexpr (GramExponentT::num < 0) {
60 return reference * mp_units::pow<num, GramExponentT::den>(mp_units::si::gram) /
61 mp_units::pow<num, GramExponentT::den>(mp_units::si::kilogram);
79template <
typename UnitT_>
82 static constexpr auto canonical = mp_units::get_canonical_unit(UnitT_{});
83 static constexpr auto coherent = coherentUnit(canonical.reference_unit);
84 static_assert(mp_units::get_canonical_unit(coherent).mag == canonical.mag,
85 "Only coherent SI units are supported, e.g. m, kg and rad but not km, g or deg: wuzp does not convert units.");
88 using type = std::remove_cvref_t<
decltype(coherent)>;
97using UnitType =
typename internal::Normalize<std::remove_cvref_t<
decltype(UnitV_)>>::type;
108 wuzp::Unit<
UnitType<mp_units::si::kilogram * mp_units::square(mp_units::si::metre) / mp_units::square(mp_units::si::second)>>;
116 wuzp::Unit<
UnitType<mp_units::si::kilogram * mp_units::square(mp_units::si::metre) / mp_units::square(mp_units::si::second)>>;