mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 04:14:27 +02:00
Merge pull request #572 from burnpanck/bugfix/allow-lvalue-references-in-value-cast
`value_cast` of `quantity_point` should accept lvalue references
This commit is contained in:
@@ -107,7 +107,7 @@ template<Unit auto ToU, typename QP>
|
||||
[[nodiscard]] constexpr QuantityPoint auto value_cast(QP&& qp)
|
||||
{
|
||||
return quantity_point{value_cast<ToU>(std::forward<QP>(qp).quantity_from_origin_is_an_implementation_detail_),
|
||||
qp.point_origin};
|
||||
std::remove_reference_t<QP>::point_origin};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,10 +124,12 @@ template<Representation ToRep, typename QP>
|
||||
requires QuantityPoint<std::remove_cvref_t<QP>> &&
|
||||
RepresentationOf<ToRep, std::remove_reference_t<QP>::quantity_spec.character> &&
|
||||
std::constructible_from<ToRep, typename std::remove_reference_t<QP>::rep>
|
||||
[[nodiscard]] constexpr quantity_point<std::remove_reference_t<QP>::reference, QP::point_origin, ToRep> value_cast(
|
||||
QP&& qp)
|
||||
[[nodiscard]] constexpr quantity_point<std::remove_reference_t<QP>::reference,
|
||||
std::remove_reference_t<QP>::point_origin, ToRep>
|
||||
value_cast(QP&& qp)
|
||||
{
|
||||
return {value_cast<ToRep>(std::forward<QP>(qp).quantity_from_origin_is_an_implementation_detail_), qp.point_origin};
|
||||
return {value_cast<ToRep>(std::forward<QP>(qp).quantity_from_origin_is_an_implementation_detail_),
|
||||
std::remove_reference_t<QP>::point_origin};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +149,7 @@ template<Unit auto ToU, Representation ToRep, typename QP>
|
||||
[[nodiscard]] constexpr QuantityPoint auto value_cast(QP&& qp)
|
||||
{
|
||||
return quantity_point{value_cast<ToU, ToRep>(std::forward<QP>(qp).quantity_from_origin_is_an_implementation_detail_),
|
||||
qp.point_origin};
|
||||
std::remove_reference_t<QP>::point_origin};
|
||||
}
|
||||
|
||||
} // namespace mp_units
|
||||
|
@@ -1677,4 +1677,19 @@ static_assert(invalid_addition(5 * isq::activity[Bq], 10 / (2 * isq::time[s]), q
|
||||
static_assert(invalid_subtraction(quantity_point{5 * isq::activity[Bq]}, 10 / (2 * isq::time[s]),
|
||||
5 * isq::frequency[Hz]));
|
||||
|
||||
// value_cast
|
||||
|
||||
static_assert(value_cast<m>(quantity_point{2 * km}).quantity_from_zero().numerical_value_in(m) == 2000);
|
||||
static_assert(value_cast<km>(quantity_point{2000 * m}).quantity_from_zero().numerical_value_in(km) == 2);
|
||||
static_assert(value_cast<int>(quantity_point{1.23 * m}).quantity_from_zero().numerical_value_in(m) == 1);
|
||||
static_assert(
|
||||
value_cast<km / h>(quantity_point{2000.0 * m / (3600.0 * s)}).quantity_from_zero().numerical_value_in(km / h) == 2);
|
||||
// lvalue references in value_cast
|
||||
namespace lvalue_tests {
|
||||
constexpr quantity_point lvalue_qp{2 * km};
|
||||
static_assert(value_cast<m>(lvalue_qp).quantity_from_zero().numerical_value_in(m) == 2000);
|
||||
static_assert(value_cast<float>(lvalue_qp).quantity_from_zero().numerical_value_in(km) == 2.f);
|
||||
static_assert(value_cast<m, float>(lvalue_qp).quantity_from_zero().numerical_value_in(m) == 2000.f);
|
||||
} // namespace lvalue_tests
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user