mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-30 02:17:16 +02:00
fix: equality for dimensions fixed to provide transitivity
This commit is contained in:
@ -150,10 +150,23 @@ template<Dimension Lhs, Dimension Rhs>
|
||||
Rhs{});
|
||||
}
|
||||
|
||||
template<Dimension Lhs, Dimension Rhs>
|
||||
[[nodiscard]] consteval bool operator==(Lhs, Rhs)
|
||||
namespace detail {
|
||||
|
||||
template<auto Symbol>
|
||||
[[nodiscard]] consteval std::true_type derived_from_the_same_base_dimension(const base_dimension<Symbol>&,
|
||||
const base_dimension<Symbol>&)
|
||||
{
|
||||
return std::derived_from<Lhs, Rhs> || std::derived_from<Rhs, Lhs>;
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] consteval std::false_type derived_from_the_same_base_dimension(...) { return {}; }
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Dimension Lhs, Dimension Rhs>
|
||||
[[nodiscard]] consteval bool operator==(Lhs lhs, Rhs rhs)
|
||||
{
|
||||
return is_same_v<Lhs, Rhs> || detail::derived_from_the_same_base_dimension(lhs, rhs);
|
||||
}
|
||||
|
||||
[[nodiscard]] consteval Dimension auto inverse(Dimension auto d) { return dimension_one / d; }
|
||||
|
@ -38,7 +38,8 @@ inline constexpr struct length_ : base_dimension<"L"> {} length;
|
||||
inline constexpr struct mass_ : base_dimension<"M"> {} mass;
|
||||
inline constexpr struct time_ : base_dimension<"T"> {} time;
|
||||
|
||||
inline constexpr struct my_length_ : decltype(length) {} my_length;
|
||||
inline constexpr struct my_length1_ : decltype(length) {} my_length1;
|
||||
inline constexpr struct my_length2_ : decltype(length) {} my_length2;
|
||||
|
||||
QUANTITY_SPEC_(q_time, time);
|
||||
inline constexpr struct second_ : named_unit<"s", kind_of<q_time>> {} second;
|
||||
@ -170,7 +171,8 @@ static_assert(invalid_operations<time>);
|
||||
|
||||
// comparisons of the same dimensions
|
||||
static_assert(length == length);
|
||||
static_assert(length == my_length);
|
||||
static_assert(length == my_length1);
|
||||
static_assert(my_length1 == my_length2);
|
||||
static_assert(speed == speed);
|
||||
|
||||
// comparisons of equivalent dimensions (named vs unnamed/derived)
|
||||
|
Reference in New Issue
Block a user