forked from mpusz/mp-units
Rename as_magnitude<...>() to mag<...>()
This is easier to write and to read.
This commit is contained in:
@@ -39,8 +39,7 @@ inline constexpr bool compatible_units<exponent_list<Es...>, Us...> = (UnitOf<Us
|
||||
template<Unit... Us, typename... Es>
|
||||
constexpr Magnitude auto derived_mag(exponent_list<Es...>)
|
||||
{
|
||||
return (as_magnitude<1>() * ... *
|
||||
pow<ratio{Es::num, Es::den}>(Us::mag / dimension_unit<typename Es::dimension>::mag));
|
||||
return (mag<1>() * ... * pow<ratio{Es::num, Es::den}>(Us::mag / dimension_unit<typename Es::dimension>::mag));
|
||||
}
|
||||
|
||||
template<DerivedDimension D, Unit... Us>
|
||||
|
||||
@@ -37,7 +37,7 @@ constexpr auto magnitude_text()
|
||||
{
|
||||
constexpr auto exp10 = extract_power_of_10(M);
|
||||
|
||||
constexpr Magnitude auto base = M / pow<exp10>(as_magnitude<10>());
|
||||
constexpr Magnitude auto base = M / pow<exp10>(mag<10>());
|
||||
constexpr Magnitude auto num = numerator(base);
|
||||
constexpr Magnitude auto den = denominator(base);
|
||||
static_assert(base == num / den, "Printing rational powers, or irrational bases, not yet supported");
|
||||
@@ -72,7 +72,7 @@ constexpr auto magnitude_text()
|
||||
template<Unit U, Magnitude auto M, std::size_t SymbolLen>
|
||||
constexpr auto prefix_or_magnitude_text()
|
||||
{
|
||||
if constexpr (M == as_magnitude<1>()) {
|
||||
if constexpr (M == mag<1>()) {
|
||||
// no ratio/prefix
|
||||
return basic_fixed_string("");
|
||||
} else {
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace units {
|
||||
template<typename Rep, typename Period>
|
||||
struct quantity_like_traits<std::chrono::duration<Rep, Period>> {
|
||||
private:
|
||||
static constexpr auto mag = as_magnitude<ratio(Period::num, Period::den)>();
|
||||
static constexpr auto mag = mag<ratio(Period::num, Period::den)>();
|
||||
public:
|
||||
using dimension = isq::si::dim_time;
|
||||
using unit = downcast_unit<dimension, mag>;
|
||||
@@ -48,7 +48,7 @@ struct clock_origin : point_origin<isq::si::dim_time> {};
|
||||
template<typename C, typename Rep, typename Period>
|
||||
struct quantity_point_like_traits<std::chrono::time_point<C, std::chrono::duration<Rep, Period>>> {
|
||||
private:
|
||||
static constexpr auto mag = as_magnitude<ratio(Period::num, Period::den)>();
|
||||
static constexpr auto mag = mag<ratio(Period::num, Period::den)>();
|
||||
public:
|
||||
using origin = clock_origin<C>;
|
||||
using unit = downcast_unit<typename origin::dimension, mag>;
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
namespace units {
|
||||
|
||||
struct one : derived_unit<one> {};
|
||||
struct percent : named_scaled_unit<percent, "%", as_magnitude<ratio(1, 100)>(), one> {};
|
||||
struct percent : named_scaled_unit<percent, "%", mag<ratio(1, 100)>(), one> {};
|
||||
|
||||
/**
|
||||
* @brief Dimension one
|
||||
|
||||
@@ -596,7 +596,7 @@ constexpr auto common_magnitude(magnitude<H1, T1...>, magnitude<H2, T2...>)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// `as_magnitude()` implementation.
|
||||
// `mag()` implementation.
|
||||
|
||||
// Sometimes we need to give the compiler a "shortcut" when factorizing large numbers (specifically, numbers whose
|
||||
// _first factor_ is very large). If we don't, we can run into limits on the number of constexpr steps or iterations.
|
||||
@@ -647,7 +647,7 @@ inline constexpr auto prime_factorization_v = prime_factorization<N>::value;
|
||||
*/
|
||||
template<ratio R>
|
||||
requires(R.num > 0)
|
||||
constexpr Magnitude auto as_magnitude()
|
||||
constexpr Magnitude auto mag()
|
||||
{
|
||||
return detail::prime_factorization_v<R.num> / detail::prime_factorization_v<R.den>;
|
||||
}
|
||||
@@ -659,7 +659,7 @@ template<ratio Base, ratio Pow>
|
||||
requires(Base.num > 0)
|
||||
constexpr Magnitude auto mag_power()
|
||||
{
|
||||
return pow<Pow>(as_magnitude<Base>());
|
||||
return pow<Pow>(mag<Base>());
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
@@ -80,7 +80,7 @@ struct same_unit_reference : is_same<typename U1::reference, typename U2::refere
|
||||
* @tparam Symbol a short text representation of the unit
|
||||
*/
|
||||
template<typename Child, basic_symbol_text Symbol>
|
||||
struct named_unit : downcast_dispatch<Child, scaled_unit<as_magnitude<1>(), Child>> {
|
||||
struct named_unit : downcast_dispatch<Child, scaled_unit<mag<1>(), Child>> {
|
||||
static constexpr auto symbol = Symbol;
|
||||
};
|
||||
|
||||
@@ -126,7 +126,7 @@ struct prefixed_unit : downcast_dispatch<Child, scaled_unit<P::mag * U::mag, typ
|
||||
* @tparam Child inherited class type used by the downcasting facility (CRTP Idiom)
|
||||
*/
|
||||
template<typename Child>
|
||||
struct derived_unit : downcast_dispatch<Child, scaled_unit<as_magnitude<1>(), Child>> {};
|
||||
struct derived_unit : downcast_dispatch<Child, scaled_unit<mag<1>(), Child>> {};
|
||||
|
||||
/**
|
||||
* @brief A unit with a deduced ratio and symbol
|
||||
|
||||
Reference in New Issue
Block a user