feat: convertible quantity kinds can now be compared

This commit is contained in:
Mateusz Pusz
2023-04-03 17:44:34 +02:00
parent 9f3ea544d5
commit e6eb908503
2 changed files with 8 additions and 3 deletions

View File

@@ -509,7 +509,8 @@ template<Quantity Q1, Quantity Q2>
} }
template<Quantity Q1, Quantity Q2> template<Quantity Q1, Quantity Q2>
requires(get_kind(Q1::quantity_spec) == get_kind(Q2::quantity_spec)) && requires(implicitly_convertible_to(get_kind(Q1::quantity_spec), get_kind(Q2::quantity_spec)) ||
implicitly_convertible_to(get_kind(Q2::quantity_spec), get_kind(Q1::quantity_spec))) &&
std::three_way_comparable_with<typename Q1::rep, typename Q2::rep> std::three_way_comparable_with<typename Q1::rep, typename Q2::rep>
[[nodiscard]] constexpr auto operator<=>(const Q1& lhs, const Q2& rhs) [[nodiscard]] constexpr auto operator<=>(const Q1& lhs, const Q2& rhs)
{ {
@@ -518,7 +519,8 @@ template<Quantity Q1, Quantity Q2>
} }
template<Quantity Q1, Quantity Q2> template<Quantity Q1, Quantity Q2>
requires(get_kind(Q1::quantity_spec) == get_kind(Q2::quantity_spec)) && requires(implicitly_convertible_to(get_kind(Q1::quantity_spec), get_kind(Q2::quantity_spec)) ||
implicitly_convertible_to(get_kind(Q2::quantity_spec), get_kind(Q1::quantity_spec))) &&
std::equality_comparable_with<typename Q1::rep, typename Q2::rep> std::equality_comparable_with<typename Q1::rep, typename Q2::rep>
[[nodiscard]] constexpr bool operator==(const Q1& lhs, const Q2& rhs) [[nodiscard]] constexpr bool operator==(const Q1& lhs, const Q2& rhs)
{ {

View File

@@ -782,12 +782,15 @@ template<QuantitySpec Q>
template<QuantitySpec Q1, QuantitySpec Q2> template<QuantitySpec Q1, QuantitySpec Q2>
[[nodiscard]] consteval QuantitySpec auto common_quantity_spec(Q1 q1, Q2 q2) [[nodiscard]] consteval QuantitySpec auto common_quantity_spec(Q1 q1, Q2 q2)
requires(get_kind(q1) == get_kind(q2)) requires(implicitly_convertible_to(get_kind(q1), get_kind(q2)) ||
implicitly_convertible_to(get_kind(q2), get_kind(q1)))
{ {
if constexpr (q1 == q2) if constexpr (q1 == q2)
return q1; return q1;
else if constexpr (detail::have_common_base(q1, q2)) else if constexpr (detail::have_common_base(q1, q2))
return detail::get_common_base(q1, q2); return detail::get_common_base(q1, q2);
else if constexpr (implicitly_convertible_to(get_kind(q1), get_kind(q2)))
return get_kind(q2);
else else
return get_kind(q1); return get_kind(q1);
} }