From 75940488506df9560dd71ea86448a2e271f02c79 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 23 Aug 2023 11:42:43 +0200 Subject: [PATCH] fix: `relative_point_origin::quantity_spec` setting fixed --- src/core/include/mp-units/quantity_point.h | 13 +++++++++---- test/unit_test/static/quantity_point_test.cpp | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/core/include/mp-units/quantity_point.h b/src/core/include/mp-units/quantity_point.h index c3bfa6df..67d96037 100644 --- a/src/core/include/mp-units/quantity_point.h +++ b/src/core/include/mp-units/quantity_point.h @@ -29,16 +29,21 @@ namespace mp_units { -template +template struct absolute_point_origin { - static constexpr QuantitySpec auto quantity_spec = Q; + static constexpr QuantitySpec auto quantity_spec = QS; }; template struct relative_point_origin { static constexpr QuantityPoint auto quantity_point = QP; - static constexpr QuantitySpec auto quantity_spec = - common_quantity_spec(QP.quantity_spec, QP.point_origin.quantity_spec); + static constexpr QuantitySpec auto quantity_spec = [](){ + // select the strongest of specs + if constexpr (detail::QuantityKindSpec>) + return QP.point_origin.quantity_spec; + else + return QP.quantity_spec; + }(); static constexpr PointOrigin auto absolute_point_origin = QP.absolute_point_origin; }; diff --git a/test/unit_test/static/quantity_point_test.cpp b/test/unit_test/static/quantity_point_test.cpp index 272aedc0..3b7a320f 100644 --- a/test/unit_test/static/quantity_point_test.cpp +++ b/test/unit_test/static/quantity_point_test.cpp @@ -1156,5 +1156,22 @@ static_assert(invalid_addition(5 * activity[Bq], 10 / (2 * isq::time[s]), zero_H static_assert(invalid_subtraction(zero_Bq + 5 * activity[Bq], 10 / (2 * isq::time[s]), 5 * isq::frequency[Hz])); +///////////////////////// +// relative point origin +///////////////////////// + +template +struct absolute_po_ : absolute_point_origin {}; +template +inline constexpr absolute_po_ absolute_po; + +template +struct relative_po_ : relative_point_origin {}; +template +inline constexpr relative_po_ relative_po; + +static_assert(relative_po + isq::height(42 * m)>.quantity_spec == isq::height); +static_assert(relative_po> + isq::height(42 * m)>.quantity_spec == isq::height); +static_assert(relative_po + 42 * m>.quantity_spec == isq::height); } // namespace