From 32fcbd78291a870380c720c5901bf3a62d89f07e Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 25 May 2023 11:59:09 +0200 Subject: [PATCH] fix: `quantity_spec` ingredients sorting fixed --- src/core/include/mp_units/quantity_spec.h | 25 +++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/core/include/mp_units/quantity_spec.h b/src/core/include/mp_units/quantity_spec.h index 38073ca9..db9119e3 100644 --- a/src/core/include/mp_units/quantity_spec.h +++ b/src/core/include/mp_units/quantity_spec.h @@ -569,16 +569,29 @@ template return 1; } +// dimension_one is always the last one +// otherwise, sort by typename +template +[[nodiscard]] consteval bool ingredients_dimension_less(D1 lhs, D2 rhs) +{ + if constexpr (lhs == rhs) + return false; + else if constexpr (lhs == dimension_one) + return false; + else if constexpr (rhs == dimension_one) + return true; + else + return type_name() < type_name(); +} + template struct ingredients_less : - std::bool_constant< - (lhs_compl > rhs_compl) || - (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())> {}; + std::bool_constant<(lhs_compl > rhs_compl) || + (lhs_compl == rhs_compl && ingredients_dimension_less(Lhs::dimension, Rhs::dimension)) || + (lhs_compl == rhs_compl && Lhs::dimension == Rhs::dimension && + type_name() < type_name())> {}; template using type_list_of_ingredients_less = expr_less;