mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 12:24:26 +02:00
feat: quantity_cast
and multiplying by reference now use perfect forwarding of a number
This commit is contained in:
@@ -55,12 +55,12 @@ class quantity;
|
|||||||
*
|
*
|
||||||
* @tparam ToQS a quantity specification to use for a target quantity
|
* @tparam ToQS a quantity specification to use for a target quantity
|
||||||
*/
|
*/
|
||||||
template<QuantitySpec auto ToQ, auto R, typename Rep>
|
template<QuantitySpec auto ToQS, Quantity Q>
|
||||||
requires(interconvertible(ToQ, get_quantity_spec(R)))
|
requires(interconvertible(ToQS, get_quantity_spec(Q::reference)))
|
||||||
[[nodiscard]] constexpr Quantity auto quantity_cast(const quantity<R, Rep>& q)
|
[[nodiscard]] constexpr Quantity auto quantity_cast(Q&& q)
|
||||||
{
|
{
|
||||||
constexpr reference<ToQ, quantity<R, Rep>::unit> r;
|
constexpr reference<ToQS, Q::unit> r;
|
||||||
return q.count() * r;
|
return std::forward<Q>(q).number() * r;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mp_units
|
} // namespace mp_units
|
||||||
|
@@ -159,9 +159,9 @@ template<AssociatedUnit U1, auto Q2, auto U2>
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<Reference R, RepresentationOf<get_quantity_spec(R{}).character> Rep>
|
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;
|
void /*Use `q * (1 * r)` rather than `q * r`.*/ operator*(Quantity auto, Reference auto) = delete;
|
||||||
|
Reference in New Issue
Block a user