From 2d10a30d2758852d919ddf41c70c9202f7015b25 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 9 Jan 2025 13:44:21 +0100 Subject: [PATCH 1/6] fix: compile-time branch condition fixed in `quantity_point::point_for` --- src/core/include/mp-units/framework/quantity_point.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index 8079d5d1..28b9d7a5 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -264,7 +264,7 @@ public: template NewPO> [[nodiscard]] constexpr QuantityPointOf<(NewPO{})> auto point_for(NewPO new_origin) const { - if constexpr (is_same_v) + if constexpr (is_same_v) return *this; else return ::mp_units::quantity_point{*this - new_origin, new_origin}; From 7ed5707e314a857666248165320c6b4d2935e44b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 9 Jan 2025 13:46:42 +0100 Subject: [PATCH 2/6] 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> From e15205e47c30b62a52f0a58bdc9490aa10b51aac Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 9 Jan 2025 14:01:39 +0100 Subject: [PATCH 3/6] refactor: `point_origin_interface::op+` return type unified with the rest of the interfaces --- src/core/include/mp-units/framework/quantity_point.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index f3fa0c9c..fb582fd1 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -63,15 +63,14 @@ template Q = std::remove_cvref_t> - [[nodiscard]] friend constexpr quantity_point - operator+(PO, FwdQ&& q) + [[nodiscard]] friend constexpr QuantityPoint auto operator+(PO po, FwdQ&& q) { - return quantity_point{std::forward(q), PO{}}; + return quantity_point{std::forward(q), po}; } - template Q = std::remove_cvref_t> - [[nodiscard]] friend constexpr quantity_point - operator+(FwdQ&& q, PO po) + template Q = std::remove_cvref_t> + [[nodiscard]] friend constexpr QuantityPoint auto operator+(FwdQ&& q, PO po) { return po + std::forward(q); } From 3bac7a4876f4ba458d6644402f06faf3994fb896 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 10 Jan 2025 22:50:26 +0100 Subject: [PATCH 4/6] fix: `inverse(Quantity)` fixed for subkinds of `dimensionless` --- src/core/include/mp-units/math.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/include/mp-units/math.h b/src/core/include/mp-units/math.h index 86a412aa..420472db 100644 --- a/src/core/include/mp-units/math.h +++ b/src/core/include/mp-units/math.h @@ -444,13 +444,17 @@ template * @brief Computes the inverse of a quantity in a provided unit */ template -[[nodiscard]] constexpr QuantityOf auto inverse(const quantity& q) +[[nodiscard]] constexpr Quantity auto inverse(const quantity& q) requires requires { representation_values::one(); value_cast(representation_values::one() / q); } { - return (representation_values::one() * one).force_in(To * quantity::unit) / q; + if constexpr (AssociatedUnit) { + constexpr QuantitySpec auto qs = get_quantity_spec(To) * quantity::quantity_spec; + return qs(representation_values::one() * one).force_in(To * quantity::unit) / q; + } else + return (representation_values::one() * one).force_in(To * quantity::unit) / q; } /** From c7b822ec5498ce597e6fff9b0e637143efbf9c6c Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 10 Jan 2025 22:59:56 +0100 Subject: [PATCH 5/6] fix: `point_origin_interface::op+` constraints fixed --- src/core/include/mp-units/framework/quantity_point.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index fb582fd1..a3113eac 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -68,8 +68,7 @@ struct point_origin_interface { return quantity_point{std::forward(q), po}; } - template Q = std::remove_cvref_t> + template Q = std::remove_cvref_t> [[nodiscard]] friend constexpr QuantityPoint auto operator+(FwdQ&& q, PO po) { return po + std::forward(q); From 0ba48b72f475ff3ed0f3c90a80e8b7f9939dc07e Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 10 Jan 2025 23:05:36 +0100 Subject: [PATCH 6/6] fix: `make_quantity_point` constraints fixed --- src/core/include/mp-units/framework/quantity_point.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index a3113eac..4a74a97e 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -51,8 +51,7 @@ template return is_specialization_of_zeroth_point_origin; } -template Q = std::remove_cvref_t> +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{}))