mirror of
https://github.com/Xahau/xahaud.git
synced 2026-06-07 18:56:36 +00:00
Use <=> operator for base_uint, Issue, and Book: (#4411)
- Implement the `operator==` and the `operator<=>` (aka the spaceship operator) in `base_uint`, `Issue`, and `Book`. - C++20-compliant compilers automatically provide the remaining comparison operators (e.g. `operator<`, `operator<=`, ...). - Remove the function compare() because it is no longer needed. - Maintain the same semantics as the existing code. - Add some unit tests to gain further confidence. - Fix #2525.
This commit is contained in:
@@ -47,58 +47,4 @@ reversed(Book const& book)
|
||||
return Book(book.out, book.in);
|
||||
}
|
||||
|
||||
/** Ordered comparison. */
|
||||
int
|
||||
compare(Book const& lhs, Book const& rhs)
|
||||
{
|
||||
int const diff(compare(lhs.in, rhs.in));
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
return compare(lhs.out, rhs.out);
|
||||
}
|
||||
|
||||
/** Equality comparison. */
|
||||
/** @{ */
|
||||
bool
|
||||
operator==(Book const& lhs, Book const& rhs)
|
||||
{
|
||||
return (lhs.in == rhs.in) && (lhs.out == rhs.out);
|
||||
}
|
||||
|
||||
bool
|
||||
operator!=(Book const& lhs, Book const& rhs)
|
||||
{
|
||||
return (lhs.in != rhs.in) || (lhs.out != rhs.out);
|
||||
}
|
||||
/** @} */
|
||||
|
||||
/** Strict weak ordering. */
|
||||
/** @{ */
|
||||
bool
|
||||
operator<(Book const& lhs, Book const& rhs)
|
||||
{
|
||||
int const diff(compare(lhs.in, rhs.in));
|
||||
if (diff != 0)
|
||||
return diff < 0;
|
||||
return lhs.out < rhs.out;
|
||||
}
|
||||
|
||||
bool
|
||||
operator>(Book const& lhs, Book const& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
bool
|
||||
operator>=(Book const& lhs, Book const& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
bool
|
||||
operator<=(Book const& lhs, Book const& rhs)
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user