diff --git a/src/core/include/mp_units/unit.h b/src/core/include/mp_units/unit.h index ed98bb52..869eeaed 100644 --- a/src/core/include/mp_units/unit.h +++ b/src/core/include/mp_units/unit.h @@ -480,35 +480,43 @@ template namespace detail { -[[nodiscard]] consteval bool same_canonical_reference_unit(...) { return false; } +[[nodiscard]] consteval bool have_same_canonical_reference_unit_impl(...) { return false; } template -[[nodiscard]] consteval bool same_canonical_reference_unit(const named_unit&, - const named_unit&) +[[nodiscard]] consteval bool have_same_canonical_reference_unit_impl(const named_unit&, + const named_unit&) { return true; } template -[[nodiscard]] consteval bool same_canonical_reference_unit(const power&, const power&) +[[nodiscard]] consteval bool have_same_canonical_reference_unit_impl(const power&, const power&) { - return same_canonical_reference_unit(F1{}, F2{}); + return have_same_canonical_reference_unit_impl(F1{}, F2{}); } template requires(sizeof...(Us1) == sizeof...(Us2)) -[[nodiscard]] consteval bool same_canonical_reference_unit(const type_list&, const type_list&) +[[nodiscard]] consteval bool have_same_canonical_reference_unit_impl(const type_list&, const type_list&) { - return (... && same_canonical_reference_unit(Us1{}, Us2{})); + return (... && have_same_canonical_reference_unit_impl(Us1{}, Us2{})); } template -[[nodiscard]] consteval bool same_canonical_reference_unit(const derived_unit&, const derived_unit&) +[[nodiscard]] consteval bool have_same_canonical_reference_unit_impl(const derived_unit&, + const derived_unit&) { - return same_canonical_reference_unit(typename derived_unit::_num_{}, - typename derived_unit::_num_{}) && - same_canonical_reference_unit(typename derived_unit::_den_{}, - typename derived_unit::_den_{}); + return have_same_canonical_reference_unit_impl(typename derived_unit::_num_{}, + typename derived_unit::_num_{}) && + have_same_canonical_reference_unit_impl(typename derived_unit::_den_{}, + typename derived_unit::_den_{}); +} + +[[nodiscard]] consteval bool have_same_canonical_reference_unit(Unit auto u1, Unit auto u2) +{ + auto canonical_lhs = detail::get_canonical_unit(u1); + auto canonical_rhs = detail::get_canonical_unit(u2); + return have_same_canonical_reference_unit_impl(canonical_lhs.reference_unit, canonical_rhs.reference_unit); } } // namespace detail @@ -518,16 +526,14 @@ template { auto canonical_lhs = detail::get_canonical_unit(lhs); auto canonical_rhs = detail::get_canonical_unit(rhs); - return detail::same_canonical_reference_unit(canonical_lhs.reference_unit, canonical_rhs.reference_unit) && + return detail::have_same_canonical_reference_unit(canonical_lhs.reference_unit, canonical_rhs.reference_unit) && canonical_lhs.mag == canonical_rhs.mag; } -// Interconvertible -[[nodiscard]] consteval bool interconvertible(Unit auto u1, Unit auto u2) +// convertible_to +[[nodiscard]] consteval bool convertible_to(Unit auto u1, Unit auto u2) { - auto canonical_lhs = detail::get_canonical_unit(u1); - auto canonical_rhs = detail::get_canonical_unit(u2); - return detail::same_canonical_reference_unit(canonical_lhs.reference_unit, canonical_rhs.reference_unit); + return detail::have_same_canonical_reference_unit(u1, u2); } // Common unit @@ -535,7 +541,7 @@ template template [[nodiscard]] consteval auto common_unit(U1 u1, U2 u2) - requires(interconvertible(u1, u2)) + requires(detail::have_same_canonical_reference_unit(u1, u2)) { if constexpr (U1{} == U2{}) { if constexpr (std::derived_from)