From bb6c942e0c36d54440a5827643cb2d415beee2bf Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 8 Feb 2023 22:15:44 -0800 Subject: [PATCH] refactor: common_quantity_spec now starts with a check of arguments equality --- src/core/include/mp_units/quantity_spec.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/include/mp_units/quantity_spec.h b/src/core/include/mp_units/quantity_spec.h index 126a2961..fafa2b64 100644 --- a/src/core/include/mp_units/quantity_spec.h +++ b/src/core/include/mp_units/quantity_spec.h @@ -529,14 +529,16 @@ template [[nodiscard]] consteval QuantitySpec auto common_quantity_spec(Q1 q1, Q2 q2) requires(get_kind(q1) == get_kind(q2)) { - if constexpr (detail::have_common_base(q1, q2)) - return detail::find_common_base(q1, q2); + if constexpr (q1 == q2) + return q1; + else if constexpr (detail::have_common_base(q1, q2)) + return detail::get_common_base(q1, q2); else return get_kind(q1); } -[[nodiscard]] consteval auto common_quantity_spec(QuantitySpec auto q1, QuantitySpec auto q2, QuantitySpec auto q3, - QuantitySpec auto... rest) +[[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q1, QuantitySpec auto q2, + QuantitySpec auto q3, QuantitySpec auto... rest) requires requires { common_quantity_spec(common_quantity_spec(q1, q2), q3, rest...); } { return common_quantity_spec(common_quantity_spec(q1, q2), q3, rest...);