refactor: convertible(U1, U2) implementation simplified

This commit is contained in:
Mateusz Pusz
2024-10-01 21:37:31 +02:00
parent 246defb9b2
commit 0d00be067a

View File

@@ -130,17 +130,18 @@ using type_list_of_unit_less = expr_less<T1, T2, unit_less>;
// Even though it is not exported, it is visible to the other module via ADL // Even though it is not exported, it is visible to the other module via ADL
[[nodiscard]] consteval auto get_canonical_unit(Unit auto u) { return detail::get_canonical_unit_impl(u, u); } [[nodiscard]] consteval auto get_canonical_unit(Unit auto u) { return detail::get_canonical_unit_impl(u, u); }
namespace detail { // convertible
template<Unit From, Unit To>
template<Unit U1, Unit U2> [[nodiscard]] consteval bool convertible(From from, To to)
[[nodiscard]] consteval bool have_same_canonical_reference_unit(U1 u1, U2 u2)
{ {
if constexpr (is_same_v<U1, U2>) if constexpr (is_same_v<From, To>)
return true; return true;
else else
return is_same_v<decltype(get_canonical_unit(u1).reference_unit), decltype(get_canonical_unit(u2).reference_unit)>; return is_same_v<decltype(get_canonical_unit(from).reference_unit),
decltype(get_canonical_unit(to).reference_unit)>;
} }
namespace detail {
struct unit_interface { struct unit_interface {
/** /**
@@ -670,16 +671,6 @@ inline constexpr auto ppm = parts_per_million;
// clang-format on // clang-format on
// convertible
template<Unit From, Unit To>
[[nodiscard]] consteval bool convertible(From from, To to)
{
if constexpr (is_same_v<From, To>)
return true;
else
return detail::have_same_canonical_reference_unit(from, to);
}
// Common unit // Common unit
[[nodiscard]] consteval Unit auto get_common_unit(Unit auto u) { return u; } [[nodiscard]] consteval Unit auto get_common_unit(Unit auto u) { return u; }