From eaca8d073a7aa7ce4f3faa8d0bb42293d6862d26 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 14 May 2023 12:58:32 +0200 Subject: [PATCH] refactor: `convertible_to_result` renamed to `convertible_result` --- src/core/include/mp_units/quantity_spec.h | 310 +++++++++---------- test/unit_test/static/quantity_spec_test.cpp | 2 +- 2 files changed, 152 insertions(+), 160 deletions(-) diff --git a/src/core/include/mp_units/quantity_spec.h b/src/core/include/mp_units/quantity_spec.h index c5162aca..80274eee 100644 --- a/src/core/include/mp_units/quantity_spec.h +++ b/src/core/include/mp_units/quantity_spec.h @@ -80,8 +80,7 @@ template } template -struct quantity_spec_less : std::bool_constant() < type_name()> { -}; +struct quantity_spec_less : std::bool_constant() < type_name()> {}; template using type_list_of_quantity_spec_less = expr_less; @@ -451,8 +450,7 @@ inline constexpr kind_of_ kind_of; namespace detail { template<> -struct is_dimensionless : std::true_type { -}; +struct is_dimensionless : std::true_type {}; template [[nodiscard]] consteval QuantitySpec auto clone_kind_of(Q q) @@ -540,7 +538,7 @@ template namespace detail { -enum class convertible_to_result { no, cast, explicit_conversion, yes }; +enum class convertible_result { no, cast, explicit_conversion, yes }; template [[nodiscard]] consteval int get_complexity(Q); @@ -583,8 +581,7 @@ struct ingredients_less : (lhs_compl == rhs_compl && (Lhs::dimension != Rhs::dimension && Rhs::dimension == dimension_one) || type_name>() < type_name>()) || - (lhs_compl == rhs_compl && Lhs::dimension == Rhs::dimension && type_name() < type_name())> { -}; + (lhs_compl == rhs_compl && Lhs::dimension == Rhs::dimension && type_name() < type_name())> {}; template using type_list_of_ingredients_less = expr_less; @@ -602,7 +599,7 @@ template template struct explode_to_equation_result { Q equation; - convertible_to_result convertible_result; + convertible_result result; }; template @@ -610,7 +607,7 @@ template [[nodiscard]] consteval auto explode_to_equation(Q q) { return explode_to_equation_result{ - Q::_equation_, defines_equation(q) ? convertible_to_result::yes : convertible_to_result::explicit_conversion}; + Q::_equation_, defines_equation(q) ? convertible_result::yes : convertible_result::explicit_conversion}; } template @@ -618,20 +615,20 @@ template [[nodiscard]] consteval auto explode_to_equation(power) { constexpr ratio exp = power::exponent; - return explode_to_equation_result{ - pow(Q::_equation_), - defines_equation(Q{}) ? convertible_to_result::yes : convertible_to_result::explicit_conversion}; + return explode_to_equation_result{pow(Q::_equation_), defines_equation(Q{}) + ? convertible_result::yes + : convertible_result::explicit_conversion}; } template struct explode_result { Q quantity; - convertible_to_result convertible_result = convertible_to_result::yes; + convertible_result result = convertible_result::yes; template [[nodiscard]] consteval explode_result common_convertibility_with(explode_to_equation_result res) const { - return {quantity, std::min(convertible_result, res.convertible_result)}; + return {quantity, std::min(result, res.result)}; } }; @@ -721,67 +718,66 @@ template template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list num_from, - type_list den_from, - type_list num_to, - type_list den_to); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list num_from, + type_list den_from, + type_list num_to, + type_list den_to); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list, - type_list, - type_list); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list, + type_list, + type_list); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, type_list<>, - type_list, - type_list); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, type_list<>, + type_list, + type_list); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, - type_list, type_list<>, - type_list); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, + type_list, type_list<>, + type_list); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, - type_list, - type_list, type_list<>); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, + type_list, + type_list, type_list<>); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, type_list<>, - type_list, type_list<>); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, type_list<>, + type_list, type_list<>); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list, - type_list<>, type_list); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list, + type_list<>, type_list); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, - type_list, type_list<>, - type_list<>); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, type_list, + type_list<>, type_list<>); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list<>, - type_list, type_list); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list, + type_list); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, type_list<>, - type_list<>, type_list<>); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, type_list<>, type_list<>, + type_list<>); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list, - type_list<>, type_list<>); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list, type_list<>, + type_list<>); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list<>, - type_list, type_list<>); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list, + type_list<>); template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>, - type_list); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>, + type_list); -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>, - type_list<>); +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>, + type_list<>); enum class prepend_rest { no, first, second }; @@ -837,8 +833,8 @@ template enum class process_entities { numerators, denominators, from, to }; template -[[nodiscard]] consteval convertible_to_result process_extracted(NumFrom num_from, DenFrom den_from, NumTo num_to, - DenTo den_to) +[[nodiscard]] consteval convertible_result process_extracted(NumFrom num_from, DenFrom den_from, NumTo num_to, + DenTo den_to) { if constexpr (Entities == process_entities::numerators || Entities == process_entities::denominators) { constexpr auto res = convertible_impl(Ext.from, Ext.to); @@ -884,10 +880,10 @@ template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list num_from, - type_list den_from, - type_list num_to, - type_list den_to) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list num_from, + type_list den_from, + type_list num_to, + type_list den_to) { if constexpr (constexpr auto extN = extract_convertible_quantities(NumFrom{}, NumTo{}); extN.same_dimension) return process_extracted(type_list{}, den_from, @@ -920,27 +916,27 @@ template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<> num_from, - type_list den_from, - type_list num_to, - type_list) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<> num_from, + type_list den_from, + type_list num_to, + type_list) { if constexpr (constexpr auto extD = extract_convertible_quantities(DenFrom{}, DenTo{}); extD.same_dimension) return process_extracted(num_from, type_list{}, num_to, @@ -961,27 +957,27 @@ template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list num_from, - type_list<> den_from, - type_list, - type_list den_to) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list num_from, + type_list<> den_from, + type_list, + type_list den_to) { if constexpr (constexpr auto extN = extract_convertible_quantities(NumFrom{}, NumTo{}); extN.same_dimension) return process_extracted(type_list{}, den_from, @@ -1002,26 +998,26 @@ template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list num_from, - type_list, - type_list<> num_to, - type_list den_to) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list num_from, + type_list, + type_list<> num_to, + type_list den_to) { if constexpr (constexpr auto extD = extract_convertible_quantities(DenFrom{}, DenTo{}); extD.same_dimension) return process_extracted(num_from, type_list{}, num_to, @@ -1047,22 +1043,21 @@ template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, - type_list den_from, - type_list num_to, - type_list<> den_to) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, + type_list den_from, + type_list num_to, + type_list<> den_to) { if constexpr (constexpr auto extN = extract_convertible_quantities(NumFrom{}, NumTo{}); extN.same_dimension) return process_extracted(type_list{}, den_from, @@ -1088,20 +1083,19 @@ template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, - type_list<> den_from, - type_list, - type_list<> den_to) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, + type_list<> den_from, + type_list, type_list<> den_to) { if constexpr (constexpr auto ext = extract_convertible_quantities(NumFrom{}, NumTo{}); ext.same_dimension) { return process_extracted(type_list{}, den_from, @@ -1117,19 +1111,18 @@ template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<> num_from, - type_list, - type_list<> num_to, - type_list) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<> num_from, + type_list, + type_list<> num_to, type_list) { if constexpr (constexpr auto ext = extract_convertible_quantities(DenFrom{}, DenTo{}); ext.same_dimension) return process_extracted(num_from, type_list{}, num_to, @@ -1145,84 +1138,83 @@ template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, - type_list, type_list<>, - type_list<>) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, type_list, + type_list<>, type_list<>) { if constexpr (((... * map_power(NumsFrom{})) / (... * map_power(DensFrom{}))).dimension == dimension_one) - return convertible_to_result::yes; + return convertible_result::yes; else - return convertible_to_result::no; + return convertible_result::no; } template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list<>, - type_list, type_list) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list, + type_list) { if constexpr (((... * map_power(NumsTo{})) / (... * map_power(DensTo{}))).dimension == dimension_one) - return convertible_to_result::yes; + return convertible_result::yes; else - return convertible_to_result::no; + return convertible_result::no; } template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list, type_list<>, - type_list<>, type_list<>) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list, type_list<>, type_list<>, + type_list<>) { if constexpr ((... * map_power(NumsFrom{})).dimension == dimension_one) - return convertible_to_result::yes; + return convertible_result::yes; else - return convertible_to_result::no; + return convertible_result::no; } template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list, - type_list<>, type_list<>) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list, type_list<>, + type_list<>) { if constexpr ((... * map_power(DensFrom{})).dimension == dimension_one) - return convertible_to_result::yes; + return convertible_result::yes; else - return convertible_to_result::no; + return convertible_result::no; } template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list<>, - type_list, type_list<>) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list, + type_list<>) { if constexpr ((... * map_power(NumsTo{})).dimension == dimension_one) - return convertible_to_result::yes; + return convertible_result::yes; else - return convertible_to_result::no; + return convertible_result::no; } template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>, - type_list) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>, + type_list) { if constexpr ((... * map_power(DensFrom{})).dimension == dimension_one) - return convertible_to_result::yes; + return convertible_result::yes; else - return convertible_to_result::no; + return convertible_result::no; } -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>, - type_list<>) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>, + type_list<>) { - return convertible_to_result::yes; + return convertible_result::yes; } template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(From, To) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(From, To) { return are_ingredients_convertible(type_list_sort{}, type_list_sort{}, @@ -1231,7 +1223,7 @@ template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(From, To) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(From, To) { return are_ingredients_convertible(type_list_sort{}, type_list_sort{}, @@ -1239,7 +1231,7 @@ template } template -[[nodiscard]] consteval convertible_to_result are_ingredients_convertible(From, To) +[[nodiscard]] consteval convertible_result are_ingredients_convertible(From, To) { return are_ingredients_convertible(type_list{}, type_list<>{}, type_list_sort{}, @@ -1247,9 +1239,9 @@ template } template -[[nodiscard]] consteval convertible_to_result convertible_impl(From from, To to) +[[nodiscard]] consteval convertible_result convertible_impl(From from, To to) { - using enum convertible_to_result; + using enum convertible_result; if constexpr (From::dimension != To::dimension) return no; @@ -1279,7 +1271,7 @@ template return convertible_impl(explode(from).quantity, to); else { constexpr auto res = explode(to); - return std::min(res.convertible_result, convertible_impl(from, res.quantity)); + return std::min(res.result, convertible_impl(from, res.quantity)); } } } else if constexpr (IntermediateDerivedQuantitySpec && IntermediateDerivedQuantitySpec) { @@ -1290,17 +1282,17 @@ template return convertible_impl(res.quantity, to); else if constexpr (requires { to._equation_; }) { constexpr auto eq = explode_to_equation(to); - return std::min(eq.convertible_result, convertible_impl(res.quantity, eq.equation)); + return std::min(eq.result, convertible_impl(res.quantity, eq.equation)); } else return are_ingredients_convertible(from, to); } else if constexpr (IntermediateDerivedQuantitySpec) { auto res = explode(to); if constexpr (NamedQuantitySpec>) - return std::min(res.convertible_result, convertible_impl(from, res.quantity)); + return std::min(res.result, convertible_impl(from, res.quantity)); else if constexpr (requires { from._equation_; }) - return std::min(res.convertible_result, convertible_impl(from._equation_, res.quantity)); + return std::min(res.result, convertible_impl(from._equation_, res.quantity)); else - return std::min(res.convertible_result, are_ingredients_convertible(from, to)); + return std::min(res.result, are_ingredients_convertible(from, to)); } return no; } @@ -1310,19 +1302,19 @@ template template [[nodiscard]] consteval bool implicitly_convertible(From from, To to) { - return detail::convertible_impl(from, to) == detail::convertible_to_result::yes; + return detail::convertible_impl(from, to) == detail::convertible_result::yes; } template [[nodiscard]] consteval bool explicitly_convertible(From from, To to) { - return detail::convertible_impl(from, to) >= detail::convertible_to_result::explicit_conversion; + return detail::convertible_impl(from, to) >= detail::convertible_result::explicit_conversion; } template [[nodiscard]] consteval bool castable(From from, To to) { - return detail::convertible_impl(from, to) >= detail::convertible_to_result::cast; + return detail::convertible_impl(from, to) >= detail::convertible_result::cast; } namespace detail { diff --git a/test/unit_test/static/quantity_spec_test.cpp b/test/unit_test/static/quantity_spec_test.cpp index d80c967d..5907819b 100644 --- a/test/unit_test/static/quantity_spec_test.cpp +++ b/test/unit_test/static/quantity_spec_test.cpp @@ -457,7 +457,7 @@ static_assert(explode(area * time / period_duration).quant static_assert(explode(pow<2>(length) * time / period_duration).quantity == pow<2>(length) * time / period_duration); -using enum convertible_to_result; +using enum convertible_result; static_assert(are_ingredients_convertible(length / time, length / time) == yes); static_assert(are_ingredients_convertible(mass * length / time, mass* length / time) == yes);