From 211bd61895b55751a3f07dba916e316c11c05d8f Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 13 Jun 2023 09:12:04 +0300 Subject: [PATCH] refactor: `sudo_cast` improved to benefit from `treat_as_floating_point` --- src/core/include/mp-units/bits/sudo_cast.h | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/core/include/mp-units/bits/sudo_cast.h b/src/core/include/mp-units/bits/sudo_cast.h index a950ad51..c60c6476 100644 --- a/src/core/include/mp-units/bits/sudo_cast.h +++ b/src/core/include/mp-units/bits/sudo_cast.h @@ -42,18 +42,6 @@ template return typename From::rep{}; } -// determines the value type used by the representation type -template -[[nodiscard]] consteval auto rep_value_type(Rep) -{ - if constexpr (requires { typename Rep::value_type; }) - return typename Rep::value_type{}; - else if constexpr (requires { typename Rep::element_type; }) - return typename Rep::element_type{}; - else - return Rep{}; -} - /** * @brief Explicit cast between different quantity types * @@ -84,10 +72,10 @@ template constexpr Magnitude auto num = numerator(c_mag); constexpr Magnitude auto den = denominator(c_mag); constexpr Magnitude auto irr = c_mag * (den / num); - using c_mag_type = common_magnitude_type; using c_rep_type = decltype(common_rep_type(q, To{})); - using v_type = decltype(rep_value_type(c_rep_type{})); - using multiplier_type = decltype(v_type{} * c_mag_type{}); + using c_mag_type = common_magnitude_type; + using multiplier_type = + conditional, std::common_type_t, c_mag_type>; constexpr auto val = [](Magnitude auto m) { return get_value(m); }; return static_cast(static_cast(std::forward(q).number()) * val(num) / val(den) * val(irr)) *