refactor: mag and mag_power changed to variable templates

This commit is contained in:
Mateusz Pusz
2022-09-15 15:13:46 -06:00
parent 70185b49c2
commit 2f365b5135
3 changed files with 25 additions and 30 deletions

View File

@@ -653,22 +653,17 @@ inline constexpr auto prime_factorization_v = prime_factorization<N>::value;
* This will be the main way end users create Magnitudes. They should rarely (if ever) create a magnitude<...> by * This will be the main way end users create Magnitudes. They should rarely (if ever) create a magnitude<...> by
* manually adding base powers. * manually adding base powers.
*/ */
template<ratio R> template<ratio R>
requires(R.num > 0) requires(R.num > 0)
constexpr Magnitude auto mag() inline constexpr Magnitude auto mag = detail::prime_factorization_v<R.num> / detail::prime_factorization_v<R.den>;
{
return detail::prime_factorization_v<R.num> / detail::prime_factorization_v<R.den>;
}
/** /**
* @brief Create a Magnitude which is some rational number raised to a rational power. * @brief Create a Magnitude which is some rational number raised to a rational power.
*/ */
template<ratio Base, ratio Pow> template<ratio Base, ratio Pow>
requires(Base.num > 0) requires(Base.num > 0)
constexpr Magnitude auto mag_power() inline constexpr Magnitude auto mag_power = pow<Pow>(mag<Base>);
{
return pow<Pow>(mag<Base>());
}
namespace detail { namespace detail {
template<typename T, BasePower auto... BPs> template<typename T, BasePower auto... BPs>

View File

@@ -103,7 +103,7 @@ template<typename T>
concept UnitSpec = Unit<T> || is_specialization_of<T, per> || detail::is_specialization_of_power<T>; concept UnitSpec = Unit<T> || is_specialization_of<T, per> || detail::is_specialization_of_power<T>;
template<UnitSpec... Us> template<UnitSpec... Us>
struct derived_unit : detail::expr_fractions<derived_unit<>, Us...>, scaled_unit<mag<1>(), derived_unit<Us...>> {}; struct derived_unit : detail::expr_fractions<derived_unit<>, Us...>, scaled_unit<mag<1>, derived_unit<Us...>> {};
// : detail::normalized_dimension<derived_dimension<>, Ds...> {}; // : detail::normalized_dimension<derived_dimension<>, Ds...> {};
@@ -127,7 +127,7 @@ template<basic_symbol_text Symbol, auto...>
struct named_unit; struct named_unit;
template<basic_symbol_text Symbol> template<basic_symbol_text Symbol>
struct named_unit<Symbol> : scaled_unit<mag<1>(), named_unit<Symbol>> { struct named_unit<Symbol> : scaled_unit<mag<1>, named_unit<Symbol>> {
static constexpr auto symbol = Symbol; static constexpr auto symbol = Symbol;
}; };

View File

@@ -27,44 +27,44 @@
namespace units::isq::si { namespace units::isq::si {
template<NamedUnit auto U> template<NamedUnit auto U>
struct yocto : prefixed_unit<"y", pow<-24>(mag<10>()), U> {}; struct yocto : prefixed_unit<"y", mag_power<10, -24>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct zepto : prefixed_unit<"z", pow<-21>(mag<10>()), U> {}; struct zepto : prefixed_unit<"z", mag_power<10, -21>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct atto : prefixed_unit<"a", pow<-18>(mag<10>()), U> {}; struct atto : prefixed_unit<"a", mag_power<10, -18>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct femto : prefixed_unit<"f", pow<-15>(mag<10>()), U> {}; struct femto : prefixed_unit<"f", mag_power<10, -15>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct pico : prefixed_unit<"p", pow<-12>(mag<10>()), U> {}; struct pico : prefixed_unit<"p", mag_power<10, -12>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct nano : prefixed_unit<"n", pow<-9>(mag<10>()), U> {}; struct nano : prefixed_unit<"n", mag_power<10, -9>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct micro : prefixed_unit<basic_symbol_text{"\u00b5", "u"}, pow<-6>(mag<10>()), U> {}; struct micro : prefixed_unit<basic_symbol_text{"\u00b5", "u"}, mag_power<10, -6>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct milli : prefixed_unit<"m", pow<-3>(mag<10>()), U> {}; struct milli : prefixed_unit<"m", mag_power<10, -3>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct centi : prefixed_unit<"c", pow<-2>(mag<10>()), U> {}; struct centi : prefixed_unit<"c", mag_power<10, -2>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct deci : prefixed_unit<"d", pow<-1>(mag<10>()), U> {}; struct deci : prefixed_unit<"d", mag_power<10, -1>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct deca : prefixed_unit<"da", pow<1>(mag<10>()), U> {}; struct deca : prefixed_unit<"da", mag_power<10, 1>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct hecto : prefixed_unit<"h", pow<2>(mag<10>()), U> {}; struct hecto : prefixed_unit<"h", mag_power<10, 2>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct kilo : prefixed_unit<"k", pow<3>(mag<10>()), U> {}; struct kilo : prefixed_unit<"k", mag_power<10, 3>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct mega : prefixed_unit<"M", pow<6>(mag<10>()), U> {}; struct mega : prefixed_unit<"M", mag_power<10, 6>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct giga : prefixed_unit<"G", pow<9>(mag<10>()), U> {}; struct giga : prefixed_unit<"G", mag_power<10, 9>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct tera : prefixed_unit<"T", pow<12>(mag<10>()), U> {}; struct tera : prefixed_unit<"T", mag_power<10, 12>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct peta : prefixed_unit<"P", pow<15>(mag<10>()), U> {}; struct peta : prefixed_unit<"P", mag_power<10, 15>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct exa : prefixed_unit<"E", pow<18>(mag<10>()), U> {}; struct exa : prefixed_unit<"E", mag_power<10, 18>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct zetta : prefixed_unit<"Z", pow<21>(mag<10>()), U> {}; struct zetta : prefixed_unit<"Z", mag_power<10, 21>, U> {};
template<NamedUnit auto U> template<NamedUnit auto U>
struct yotta : prefixed_unit<"Y", pow<24>(mag<10>()), U> {}; struct yotta : prefixed_unit<"Y", mag_power<10, 24>, U> {};
} // namespace units::isq::si } // namespace units::isq::si