feat: quantity_cast and multiplying by reference now use perfect forwarding of a number

This commit is contained in:
Mateusz Pusz
2023-02-03 15:22:54 +01:00
parent 7dd5580afb
commit cd0ee9276b
2 changed files with 7 additions and 7 deletions

View File

@@ -55,12 +55,12 @@ class quantity;
*
* @tparam ToQS a quantity specification to use for a target quantity
*/
template<QuantitySpec auto ToQ, auto R, typename Rep>
requires(interconvertible(ToQ, get_quantity_spec(R)))
[[nodiscard]] constexpr Quantity auto quantity_cast(const quantity<R, Rep>& q)
template<QuantitySpec auto ToQS, Quantity Q>
requires(interconvertible(ToQS, get_quantity_spec(Q::reference)))
[[nodiscard]] constexpr Quantity auto quantity_cast(Q&& q)
{
constexpr reference<ToQ, quantity<R, Rep>::unit> r;
return q.count() * r;
constexpr reference<ToQS, Q::unit> r;
return std::forward<Q>(q).number() * r;
}
} // namespace mp_units

View File

@@ -159,9 +159,9 @@ template<AssociatedUnit U1, auto Q2, auto U2>
}
template<Reference R, RepresentationOf<get_quantity_spec(R{}).character> Rep>
[[nodiscard]] constexpr quantity<R{}, Rep> operator*(const Rep& lhs, R)
[[nodiscard]] constexpr quantity<R{}, Rep> operator*(Rep&& lhs, R)
{
return quantity<R{}, Rep>(lhs);
return quantity<R{}, Rep>(std::forward<Rep>(lhs));
}
void /*Use `q * (1 * r)` rather than `q * r`.*/ operator*(Quantity auto, Reference auto) = delete;