mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 05:04:27 +02:00
feat: convertible quantity kinds can now be compared
This commit is contained in:
@@ -509,7 +509,8 @@ 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>
|
||||
[[nodiscard]] constexpr auto operator<=>(const Q1& lhs, const Q2& rhs)
|
||||
{
|
||||
@@ -518,7 +519,8 @@ 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>
|
||||
[[nodiscard]] constexpr bool operator==(const Q1& lhs, const Q2& rhs)
|
||||
{
|
||||
|
@@ -782,12 +782,15 @@ template<QuantitySpec Q>
|
||||
|
||||
template<QuantitySpec Q1, QuantitySpec 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)
|
||||
return q1;
|
||||
else if constexpr (detail::have_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
|
||||
return get_kind(q1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user