From 2f365b51354c49646322411ca8e43cad6c4369f3 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 15 Sep 2022 15:13:46 -0600 Subject: [PATCH] refactor: `mag` and `mag_power` changed to variable templates --- src/core/include/units/magnitude.h | 11 ++--- src/core/include/units/unit.h | 4 +- .../si/include/units/isq/si/prefixes.h | 40 +++++++++---------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/core/include/units/magnitude.h b/src/core/include/units/magnitude.h index d0bd6501..5f27f66c 100644 --- a/src/core/include/units/magnitude.h +++ b/src/core/include/units/magnitude.h @@ -653,22 +653,17 @@ inline constexpr auto prime_factorization_v = prime_factorization::value; * This will be the main way end users create Magnitudes. They should rarely (if ever) create a magnitude<...> by * manually adding base powers. */ + template requires(R.num > 0) -constexpr Magnitude auto mag() -{ - return detail::prime_factorization_v / detail::prime_factorization_v; -} +inline constexpr Magnitude auto mag = detail::prime_factorization_v / detail::prime_factorization_v; /** * @brief Create a Magnitude which is some rational number raised to a rational power. */ template requires(Base.num > 0) -constexpr Magnitude auto mag_power() -{ - return pow(mag()); -} +inline constexpr Magnitude auto mag_power = pow(mag); namespace detail { template diff --git a/src/core/include/units/unit.h b/src/core/include/units/unit.h index 5081cb5b..d3c5b068 100644 --- a/src/core/include/units/unit.h +++ b/src/core/include/units/unit.h @@ -103,7 +103,7 @@ template concept UnitSpec = Unit || is_specialization_of || detail::is_specialization_of_power; template -struct derived_unit : detail::expr_fractions, Us...>, scaled_unit(), derived_unit> {}; +struct derived_unit : detail::expr_fractions, Us...>, scaled_unit, derived_unit> {}; // : detail::normalized_dimension, Ds...> {}; @@ -127,7 +127,7 @@ template struct named_unit; template -struct named_unit : scaled_unit(), named_unit> { +struct named_unit : scaled_unit, named_unit> { static constexpr auto symbol = Symbol; }; diff --git a/src/systems/si/include/units/isq/si/prefixes.h b/src/systems/si/include/units/isq/si/prefixes.h index e150426e..5ecd21e6 100644 --- a/src/systems/si/include/units/isq/si/prefixes.h +++ b/src/systems/si/include/units/isq/si/prefixes.h @@ -27,44 +27,44 @@ namespace units::isq::si { template -struct yocto : prefixed_unit<"y", pow<-24>(mag<10>()), U> {}; +struct yocto : prefixed_unit<"y", mag_power<10, -24>, U> {}; template -struct zepto : prefixed_unit<"z", pow<-21>(mag<10>()), U> {}; +struct zepto : prefixed_unit<"z", mag_power<10, -21>, U> {}; template -struct atto : prefixed_unit<"a", pow<-18>(mag<10>()), U> {}; +struct atto : prefixed_unit<"a", mag_power<10, -18>, U> {}; template -struct femto : prefixed_unit<"f", pow<-15>(mag<10>()), U> {}; +struct femto : prefixed_unit<"f", mag_power<10, -15>, U> {}; template -struct pico : prefixed_unit<"p", pow<-12>(mag<10>()), U> {}; +struct pico : prefixed_unit<"p", mag_power<10, -12>, U> {}; template -struct nano : prefixed_unit<"n", pow<-9>(mag<10>()), U> {}; +struct nano : prefixed_unit<"n", mag_power<10, -9>, U> {}; template -struct micro : prefixed_unit(mag<10>()), U> {}; +struct micro : prefixed_unit, U> {}; template -struct milli : prefixed_unit<"m", pow<-3>(mag<10>()), U> {}; +struct milli : prefixed_unit<"m", mag_power<10, -3>, U> {}; template -struct centi : prefixed_unit<"c", pow<-2>(mag<10>()), U> {}; +struct centi : prefixed_unit<"c", mag_power<10, -2>, U> {}; template -struct deci : prefixed_unit<"d", pow<-1>(mag<10>()), U> {}; +struct deci : prefixed_unit<"d", mag_power<10, -1>, U> {}; template -struct deca : prefixed_unit<"da", pow<1>(mag<10>()), U> {}; +struct deca : prefixed_unit<"da", mag_power<10, 1>, U> {}; template -struct hecto : prefixed_unit<"h", pow<2>(mag<10>()), U> {}; +struct hecto : prefixed_unit<"h", mag_power<10, 2>, U> {}; template -struct kilo : prefixed_unit<"k", pow<3>(mag<10>()), U> {}; +struct kilo : prefixed_unit<"k", mag_power<10, 3>, U> {}; template -struct mega : prefixed_unit<"M", pow<6>(mag<10>()), U> {}; +struct mega : prefixed_unit<"M", mag_power<10, 6>, U> {}; template -struct giga : prefixed_unit<"G", pow<9>(mag<10>()), U> {}; +struct giga : prefixed_unit<"G", mag_power<10, 9>, U> {}; template -struct tera : prefixed_unit<"T", pow<12>(mag<10>()), U> {}; +struct tera : prefixed_unit<"T", mag_power<10, 12>, U> {}; template -struct peta : prefixed_unit<"P", pow<15>(mag<10>()), U> {}; +struct peta : prefixed_unit<"P", mag_power<10, 15>, U> {}; template -struct exa : prefixed_unit<"E", pow<18>(mag<10>()), U> {}; +struct exa : prefixed_unit<"E", mag_power<10, 18>, U> {}; template -struct zetta : prefixed_unit<"Z", pow<21>(mag<10>()), U> {}; +struct zetta : prefixed_unit<"Z", mag_power<10, 21>, U> {}; template -struct yotta : prefixed_unit<"Y", pow<24>(mag<10>()), U> {}; +struct yotta : prefixed_unit<"Y", mag_power<10, 24>, U> {}; } // namespace units::isq::si