mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-07 06:04:27 +02:00
fix: quantity.in(U)
fixed to clone a reference from the source type
This commit is contained in:
@@ -163,8 +163,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<Unit U>
|
template<Unit U>
|
||||||
requires detail::QuantityConvertibleTo<quantity, quantity<::mp_units::reference<quantity_spec, U{}>{}, Rep>>
|
requires detail::QuantityConvertibleTo<quantity, quantity<quantity_spec[U{}], Rep>>
|
||||||
[[nodiscard]] constexpr quantity<::mp_units::reference<quantity_spec, U{}>{}, Rep> in(U) const
|
[[nodiscard]] constexpr quantity<quantity_spec[U{}], Rep> in(U) const
|
||||||
{
|
{
|
||||||
return quantity<quantity_spec[U{}], Rep>{*this};
|
return quantity<quantity_spec[U{}], Rep>{*this};
|
||||||
}
|
}
|
||||||
|
@@ -200,6 +200,10 @@ static_assert(quantity<isq::length[km]>(1500 * m).numerical_value() == 1.5);
|
|||||||
// converting to a different unit
|
// converting to a different unit
|
||||||
///////////////////////////////////
|
///////////////////////////////////
|
||||||
|
|
||||||
|
static_assert(is_of_type<(2. * km).in(m), quantity<si::metre>>);
|
||||||
|
static_assert(is_of_type<isq::length(2. * km).in(m), quantity<isq::length[m]>>);
|
||||||
|
static_assert(is_of_type<isq::height(2. * km).in(m), quantity<isq::height[m]>>);
|
||||||
|
|
||||||
static_assert(quantity<isq::length[km]>(2. * km).in(km).numerical_value() == 2.);
|
static_assert(quantity<isq::length[km]>(2. * km).in(km).numerical_value() == 2.);
|
||||||
static_assert(quantity<isq::length[km]>(2. * km).in(m).numerical_value() == 2000.);
|
static_assert(quantity<isq::length[km]>(2. * km).in(m).numerical_value() == 2000.);
|
||||||
static_assert(quantity<isq::length[m]>(2000. * m).in(km).numerical_value() == 2.);
|
static_assert(quantity<isq::length[m]>(2000. * m).in(km).numerical_value() == 2.);
|
||||||
|
Reference in New Issue
Block a user