From 1c8b8ff8e9fc7dafdd73e6aa8415703792ba57e6 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 27 Sep 2024 19:16:11 +0200 Subject: [PATCH] fix: missing `are_ingredients_convertible` overloads added --- .../mp-units/framework/quantity_spec.h | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 3de958af..7e8f0b35 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -411,16 +411,12 @@ struct quantity_spec : detail::propagate_equation, detail #if MP_UNITS_API_NO_CRTP template auto... Args> - requires(!requires { QS._equation_; } || - ((requires { QS._equation_; }) && detail::QuantitySpecExplicitlyConvertibleTo)) && - (... && !QuantitySpec) + requires(detail::QuantitySpecExplicitlyConvertibleTo) && (... && !QuantitySpec) struct quantity_spec : detail::quantity_spec_interface { #else template auto... Args> - requires(!requires { QS._equation_; } || - ((requires { QS._equation_; }) && detail::QuantitySpecExplicitlyConvertibleTo)) && - (... && !QuantitySpec) + requires(detail::QuantitySpecExplicitlyConvertibleTo) && (... && !QuantitySpec) struct quantity_spec : detail::quantity_spec_interface { #endif using _base_type_ = quantity_spec; @@ -1259,6 +1255,48 @@ template +[[nodiscard]] consteval specs_convertible_result are_ingredients_convertible(type_list, + type_list<>, type_list<>, + type_list) +{ + constexpr auto num_from_compl = get_complexity(NumFrom{}); + constexpr auto den_to_compl = get_complexity(DenTo{}); + constexpr auto max_compl = max(num_from_compl, den_to_compl); + if constexpr (max_compl > 1) { + if constexpr (num_from_compl == max_compl) { + constexpr auto res = explode_to_equation(NumFrom{}); + return convertible_impl((res.equation * ... * map_power(NumsFrom{})), + dimensionless / (map_power(DenTo{}) * ... * map_power(DensTo{}))); + } else { + constexpr auto res = explode_to_equation(DenTo{}); + return min(res.result, convertible_impl((map_power(NumFrom{}) * ... * map_power(NumsFrom{})), + dimensionless / (res.equation * ... * map_power(DensTo{})))); + } + } +} + +template +[[nodiscard]] consteval specs_convertible_result are_ingredients_convertible(type_list<>, + type_list, + type_list, type_list<>) +{ + constexpr auto den_from_compl = get_complexity(DenFrom{}); + constexpr auto num_to_compl = get_complexity(NumTo{}); + constexpr auto max_compl = max(den_from_compl, num_to_compl); + if constexpr (max_compl > 1) { + if constexpr (den_from_compl == max_compl) { + constexpr auto res = explode_to_equation(DenFrom{}); + return convertible_impl(dimensionless / (res.equation * ... * map_power(DensFrom{})), + (map_power(NumTo{}) * ... * map_power(NumsTo{}))); + } else { + constexpr auto res = explode_to_equation(NumTo{}); + return min(res.result, convertible_impl(dimensionless / (map_power(DenFrom{}) * ... * map_power(DensFrom{})), + (res.equation * ... * map_power(NumsTo{})))); + } + } +} + template [[nodiscard]] consteval specs_convertible_result are_ingredients_convertible(type_list, type_list, type_list<>,