Skip to content

Commit

Permalink
Explicit equality operator in Literal
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Urbanke committed Apr 1, 2024
1 parent df488ec commit 648d628
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions include/rfl/Literal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,32 @@ class Literal {
return *this;
}

/// Equality operator other Literals.
bool operator==(const Literal<fields_...>& _other) const {
return value() == _other.value();
/// <=> for other Literals with the same fields.
auto operator<=>(const Literal<fields_...>& _other) const {
return value() <=> _other.value();
}

/// <=> for other Literals with different fields.
template <internal::StringLiteral... _fields>
inline auto operator<=>(const Literal<_fields...>& _l2) const {
return name() <=> _l2.name();
}

/// <=> for strings.
inline auto operator<=>(const std::string& _str) const {
return name() <=> _str;
}

/// <=> for const char*.
template <internal::StringLiteral... other_fields>
inline auto operator<=>(const char* _str) const {
return name() <=> _str;
}

/// Equality operator.
template <class Other>
bool operator==(const Other& _other) const {
return (*this <=> _other) == 0;
}

/// Alias for .name().
Expand Down Expand Up @@ -335,28 +358,6 @@ inline constexpr auto value_of() {
return LiteralType::template value_of<_name>();
}

/// <=> for other Literals with the same fields.
template <internal::StringLiteral... fields>
inline auto operator<=>(const Literal<fields...>& _l1,
const Literal<fields...>& _l2) {
return _l1.value() <=> _l2.value();
}

/// <=> for other Literals with different fields.
template <internal::StringLiteral... fields1,
internal::StringLiteral... fields2>
inline auto operator<=>(const Literal<fields1...>& _l1,
const Literal<fields2...>& _l2) {
return _l1.name() <=> _l2.name();
}

/// <=> for strings.
template <internal::StringLiteral... other_fields>
inline auto operator<=>(const Literal<other_fields...>& _l,
const std::string& _str) {
return _l <=> _str;
}

} // namespace rfl

namespace std {
Expand Down

0 comments on commit 648d628

Please sign in to comment.