Skip to content

Commit fdfaefc

Browse files
committed
fix: quantity_cast support fixed for quantity_point
1 parent 06d1575 commit fdfaefc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/core/include/mp-units/framework/quantity_cast.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ template<QuantitySpec auto ToQS, typename FwdQ, Quantity Q = std::remove_cvref_t
8383
* @tparam ToQS a quantity specification to use for a target quantity point
8484
*/
8585
template<QuantitySpec auto ToQS, typename FwdQP, QuantityPoint QP = std::remove_cvref_t<FwdQP>>
86-
requires(castable(QP::quantity_spec, ToQS)) && (MP_UNITS_WEAK_UNIT_OF(MP_UNITS_NONCONST_TYPE(QP::unit), ToQS))
86+
requires(castable(QP::quantity_spec, ToQS)) &&
87+
requires { typename quantity_point<make_reference(ToQS, QP::unit), QP::point_origin, typename QP::rep>; }
8788
[[nodiscard]] constexpr QuantityPoint auto quantity_cast(FwdQP&& qp)
8889
{
89-
return QP{quantity_cast<ToQS>(std::forward<FwdQP>(qp).quantity_from_origin_is_an_implementation_detail_),
90-
QP::point_origin};
90+
return quantity_point{quantity_cast<ToQS>(std::forward<FwdQP>(qp).quantity_from_origin_is_an_implementation_detail_),
91+
qp.point_origin};
9192
}
9293

9394
} // namespace mp_units

test/static/quantity_point_test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,4 +1787,20 @@ static_assert(
17871787
static_assert(
17881788
is_of_type<kind_of<isq::length>(zeroth_length + isq::height(1 * m)), quantity_point<si::metre, zeroth_length, int>>);
17891789

1790+
1791+
//////////////////
1792+
// quantity_cast
1793+
//////////////////
1794+
1795+
static_assert(
1796+
is_of_type<quantity_cast<isq::height>(zeroth_length + 1 * m), quantity_point<isq::height[m], zeroth_length, int>>);
1797+
static_assert(is_of_type<quantity_cast<isq::height>(zeroth_length + isq::length(1 * m)),
1798+
quantity_point<isq::height[m], zeroth_length, int>>);
1799+
static_assert(is_of_type<quantity_cast<isq::height>(zeroth_length + isq::width(1 * m)),
1800+
quantity_point<isq::height[m], zeroth_length, int>>);
1801+
static_assert(is_of_type<quantity_cast<kind_of<isq::length>>(zeroth_length + isq::length(1 * m)),
1802+
quantity_point<si::metre, zeroth_length, int>>);
1803+
static_assert(is_of_type<quantity_cast<kind_of<isq::length>>(zeroth_length + isq::height(1 * m)),
1804+
quantity_point<si::metre, zeroth_length, int>>);
1805+
17901806
} // namespace

0 commit comments

Comments
 (0)