diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 530eb3599..3de958af6 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -1535,6 +1535,13 @@ template // NOLINTEND(bugprone-branch-clone) } +[[nodiscard]] consteval QuantitySpec auto get_common_quantity_spec(QuantitySpec auto q1, QuantitySpec auto q2, + QuantitySpec auto q3, QuantitySpec auto... rest) + requires requires { get_common_quantity_spec(get_common_quantity_spec(q1, q2), q3, rest...); } +{ + return get_common_quantity_spec(get_common_quantity_spec(q1, q2), q3, rest...); +} + MP_UNITS_EXPORT_END } // namespace mp_units diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index 4b64b165c..d74c5cc88 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -268,24 +268,30 @@ template // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) constexpr auto operator/(R, Q&& q) = delete; -[[nodiscard]] consteval AssociatedUnit auto get_common_reference(AssociatedUnit auto u1, AssociatedUnit auto u2) +[[nodiscard]] consteval AssociatedUnit auto get_common_reference(AssociatedUnit auto u1, AssociatedUnit auto u2, + AssociatedUnit auto... rest) requires requires { - { get_common_quantity_spec(get_quantity_spec(u1), get_quantity_spec(u2)) } -> QuantitySpec; - { get_common_unit(u1, u2) } -> AssociatedUnit; + { + get_common_quantity_spec(get_quantity_spec(u1), get_quantity_spec(u2), get_quantity_spec(rest)...) + } -> QuantitySpec; + { get_common_unit(u1, u2, rest...) } -> AssociatedUnit; } { - return get_common_unit(u1, u2); + return get_common_unit(u1, u2, rest...); } -template -[[nodiscard]] consteval Reference auto get_common_reference(R1 r1, R2 r2) - requires(!(AssociatedUnit && AssociatedUnit)) && requires { - { get_common_quantity_spec(get_quantity_spec(r1), get_quantity_spec(r2)) } -> QuantitySpec; - { get_common_unit(get_unit(r1), get_unit(r2)) } -> Unit; +template +[[nodiscard]] consteval Reference auto get_common_reference(R1 r1, R2 r2, Rest... rest) + requires(!(AssociatedUnit && AssociatedUnit && (... && AssociatedUnit))) && requires { + { + get_common_quantity_spec(get_quantity_spec(r1), get_quantity_spec(r2), get_quantity_spec(rest)...) + } -> QuantitySpec; + { get_common_unit(get_unit(r1), get_unit(r2), get_unit(rest)...) } -> Unit; } { - return detail::reference_t{}; + return detail::reference_t{}; } MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index 58f891e3b..ed79be9d3 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -654,6 +654,12 @@ template } } +[[nodiscard]] consteval Unit auto get_common_unit(Unit auto u1, Unit auto u2, Unit auto u3, Unit auto... rest) + requires requires { get_common_unit(get_common_unit(u1, u2), u3, rest...); } +{ + return get_common_unit(get_common_unit(u1, u2), u3, rest...); +} + /** * @brief Puts a space ' ' sign before a unit symbol