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;