mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 13:14:29 +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>
|
||||
requires detail::QuantityConvertibleTo<quantity, quantity<::mp_units::reference<quantity_spec, U{}>{}, Rep>>
|
||||
[[nodiscard]] constexpr quantity<::mp_units::reference<quantity_spec, U{}>{}, Rep> in(U) const
|
||||
requires detail::QuantityConvertibleTo<quantity, quantity<quantity_spec[U{}], Rep>>
|
||||
[[nodiscard]] constexpr quantity<quantity_spec[U{}], Rep> in(U) const
|
||||
{
|
||||
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
|
||||
///////////////////////////////////
|
||||
|
||||
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(m).numerical_value() == 2000.);
|
||||
static_assert(quantity<isq::length[m]>(2000. * m).in(km).numerical_value() == 2.);
|
||||
|
Reference in New Issue
Block a user