From 04588d9c8b98f8702abf9988195262d118a0374d Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 30 Sep 2023 21:36:23 -0600 Subject: [PATCH] feat: `Magnitude / Unit` operator added --- src/core/include/mp-units/unit.h | 9 +++++++++ src/systems/si/include/mp-units/systems/si/constants.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/include/mp-units/unit.h b/src/core/include/mp-units/unit.h index c4343c45..5810c4a7 100644 --- a/src/core/include/mp-units/unit.h +++ b/src/core/include/mp-units/unit.h @@ -430,6 +430,15 @@ template return detail::expr_multiply(lhs, rhs); } +/** + * Returns the result of multiplication with an inverse unit. + */ +template +[[nodiscard]] MP_UNITS_CONSTEVAL Unit auto operator/(M mag, const U u) +{ + return mag * (1 / u); +} + /** * `scaled_unit` specializations have priority in this operation. This means that the library framework * prevents passing it as an element to the `derived_unit`. In such case only the reference unit is passed diff --git a/src/systems/si/include/mp-units/systems/si/constants.h b/src/systems/si/include/mp-units/systems/si/constants.h index a0ad268d..b342ba5d 100644 --- a/src/systems/si/include/mp-units/systems/si/constants.h +++ b/src/systems/si/include/mp-units/systems/si/constants.h @@ -41,7 +41,7 @@ inline constexpr struct elementary_charge : inline constexpr struct boltzmann_constant : named_unit<"k", mag * mag_power<10, -23> * joule / kelvin> {} boltzmann_constant; inline constexpr struct avogadro_constant : - named_unit<"N_A", mag * mag_power<10, 23> * (1 / mole)> {} avogadro_constant; + named_unit<"N_A", mag * mag_power<10, 23> / mole> {} avogadro_constant; inline constexpr struct luminous_efficacy : named_unit<"K_cd", mag<683> * lumen / watt> {} luminous_efficacy; // clang-format on