From 7ed5707e314a857666248165320c6b4d2935e44b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 9 Jan 2025 13:46:42 +0100 Subject: [PATCH] refactor: `make_quantity_point` introduced --- .../mp-units/framework/quantity_point.h | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index 28b9d7a5..f3fa0c9c 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -51,6 +51,16 @@ template return is_specialization_of_zeroth_point_origin; } +template Q = std::remove_cvref_t> +[[nodiscard]] constexpr QuantityPoint auto make_quantity_point(FwdQ&& q, PO po) +{ + if constexpr (detail::is_zeroth_point_origin(PO{})) + return quantity_point{std::forward(q)}; + else + return quantity_point{std::forward(q), po}; +} + struct point_origin_interface { template Q = std::remove_cvref_t> [[nodiscard]] friend constexpr quantity_point @@ -456,10 +466,7 @@ public: [[nodiscard]] friend constexpr QuantityPoint auto operator+(const QP& qp, const quantity& q) requires requires { qp.quantity_ref_from(PO) + q; } { - if constexpr (detail::is_zeroth_point_origin(PO)) - return ::mp_units::quantity_point{qp.quantity_ref_from(PO) + q}; - else - return ::mp_units::quantity_point{qp.quantity_ref_from(PO) + q, PO}; + return detail::make_quantity_point(qp.quantity_ref_from(PO) + q, PO); } template QP> @@ -477,10 +484,7 @@ public: [[nodiscard]] friend constexpr QuantityPoint auto operator-(const QP& qp, const quantity& q) requires requires { qp.quantity_ref_from(PO) - q; } { - if constexpr (detail::is_zeroth_point_origin(PO)) - return ::mp_units::quantity_point{qp.quantity_ref_from(PO) - q}; - else - return ::mp_units::quantity_point{qp.quantity_ref_from(PO) - q, PO}; + return detail::make_quantity_point(qp.quantity_ref_from(PO) - q, PO); } template QP, QuantityPointOf QP2>