mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-02 20:04:27 +02:00
fix quantity_cast to accept lvalue references
This commit is contained in:
@@ -53,10 +53,10 @@ namespace mp_units {
|
|||||||
* @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 ToQS, typename Q>
|
template<QuantitySpec auto ToQS, typename Q>
|
||||||
requires Quantity<std::remove_cvref_t<Q>> && (castable(Q::quantity_spec, ToQS))
|
requires Quantity<std::remove_cvref_t<Q>> && (castable(std::remove_reference_t<Q>::quantity_spec, ToQS))
|
||||||
[[nodiscard]] constexpr Quantity auto quantity_cast(Q&& q)
|
[[nodiscard]] constexpr Quantity auto quantity_cast(Q&& q)
|
||||||
{
|
{
|
||||||
return quantity{std::forward<Q>(q).numerical_value_is_an_implementation_detail_, make_reference(ToQS, Q::unit)};
|
return quantity{std::forward<Q>(q).numerical_value_is_an_implementation_detail_, make_reference(ToQS, q.unit)};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,7 +77,7 @@ template<QuantitySpec auto ToQS, typename Q>
|
|||||||
* @tparam ToQS a quantity specification to use for a target quantity point
|
* @tparam ToQS a quantity specification to use for a target quantity point
|
||||||
*/
|
*/
|
||||||
template<QuantitySpec auto ToQS, typename QP>
|
template<QuantitySpec auto ToQS, typename QP>
|
||||||
requires QuantityPoint<std::remove_cvref_t<QP>> && (castable(QP::quantity_spec, ToQS))
|
requires QuantityPoint<std::remove_cvref_t<QP>> && (castable(std::remove_reference_t<QP>::quantity_spec, ToQS))
|
||||||
[[nodiscard]] constexpr QuantityPoint auto quantity_cast(QP&& qp)
|
[[nodiscard]] constexpr QuantityPoint auto quantity_cast(QP&& qp)
|
||||||
{
|
{
|
||||||
return QP{quantity_cast<ToQS>(std::forward<QP>(qp).quantity_from_origin_is_an_implementation_detail_),
|
return QP{quantity_cast<ToQS>(std::forward<QP>(qp).quantity_from_origin_is_an_implementation_detail_),
|
||||||
|
Reference in New Issue
Block a user