mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-02 20:04:27 +02:00
fix: operator*(M, U u)
fixed for U
being scaled_unit
This commit is contained in:
@@ -157,7 +157,12 @@ struct unit_interface {
|
|||||||
{
|
{
|
||||||
if constexpr (std::is_same_v<M, std::remove_const_t<decltype(mp_units::mag<1>)>>)
|
if constexpr (std::is_same_v<M, std::remove_const_t<decltype(mp_units::mag<1>)>>)
|
||||||
return u;
|
return u;
|
||||||
|
else if constexpr (is_specialization_of_scaled_unit<U>) {
|
||||||
|
if constexpr (M{} * U::mag == mag<1>)
|
||||||
|
return U::reference_unit;
|
||||||
else
|
else
|
||||||
|
return scaled_unit<M{} * U::mag, std::remove_const_t<decltype(U::reference_unit)>>{};
|
||||||
|
} else
|
||||||
return scaled_unit<M{}, U>{};
|
return scaled_unit<M{}, U>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -253,6 +253,16 @@ static_assert(is_of_type<m_2, scaled_unit<mag<2>, metre_>>);
|
|||||||
static_assert(is_of_type<get_canonical_unit(m_2).reference_unit, metre_>);
|
static_assert(is_of_type<get_canonical_unit(m_2).reference_unit, metre_>);
|
||||||
static_assert(get_canonical_unit(m_2).mag == mag<2>);
|
static_assert(get_canonical_unit(m_2).mag == mag<2>);
|
||||||
|
|
||||||
|
constexpr auto m_3 = mag_ratio<1, 2> * m_2;
|
||||||
|
static_assert(is_of_type<m_3, metre_>);
|
||||||
|
static_assert(is_of_type<get_canonical_unit(m_3).reference_unit, metre_>);
|
||||||
|
static_assert(get_canonical_unit(m_3).mag == mag<1>);
|
||||||
|
|
||||||
|
constexpr auto m_4 = mag_ratio<1, 2> * (mag<4> * metre);
|
||||||
|
static_assert(is_of_type<m_4, scaled_unit<mag<2>, metre_>>);
|
||||||
|
static_assert(is_of_type<get_canonical_unit(m_4).reference_unit, metre_>);
|
||||||
|
static_assert(get_canonical_unit(m_4).mag == mag<2>);
|
||||||
|
|
||||||
constexpr auto km_2 = mag<2> * kilometre;
|
constexpr auto km_2 = mag<2> * kilometre;
|
||||||
static_assert(is_of_type<km_2, scaled_unit<mag<2>, kilo_<metre_>>>);
|
static_assert(is_of_type<km_2, scaled_unit<mag<2>, kilo_<metre_>>>);
|
||||||
static_assert(is_of_type<get_canonical_unit(km_2).reference_unit, metre_>);
|
static_assert(is_of_type<get_canonical_unit(km_2).reference_unit, metre_>);
|
||||||
|
Reference in New Issue
Block a user