utils: big_decimal: replace compare() with <=> operator
now that we are using C++20, it'd be more convenient if we can use the <=> operator for comparing. the compiler creates the 6 other operators for us if the <=> operator is defined. so the code is more compacted. in this change, `big_decimal::compare()` is replaced with `operator<=>`, and its caller is updated accordingly. Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
This commit is contained in:
@@ -2346,7 +2346,7 @@ struct compare_visitor {
|
||||
return with_empty_checks([&] {
|
||||
auto a = deserialize_value(d, v1);
|
||||
auto b = deserialize_value(d, v2);
|
||||
return a.compare(b);
|
||||
return a <=> b;
|
||||
});
|
||||
}
|
||||
std::strong_ordering operator()(const varint_type_impl& v) {
|
||||
|
||||
@@ -135,7 +135,7 @@ sstring big_decimal::to_string() const
|
||||
return str;
|
||||
}
|
||||
|
||||
std::strong_ordering big_decimal::compare(const big_decimal& other) const
|
||||
std::strong_ordering big_decimal::operator<=>(const big_decimal& other) const
|
||||
{
|
||||
auto max_scale = std::max(_scale, other._scale);
|
||||
boost::multiprecision::cpp_int rescale(10);
|
||||
|
||||
@@ -38,19 +38,13 @@ public:
|
||||
|
||||
sstring to_string() const;
|
||||
|
||||
std::strong_ordering compare(const big_decimal& other) const;
|
||||
std::strong_ordering operator<=>(const big_decimal& other) const;
|
||||
|
||||
big_decimal& operator+=(const big_decimal& other);
|
||||
big_decimal& operator-=(const big_decimal& other);
|
||||
big_decimal operator+(const big_decimal& other) const;
|
||||
big_decimal operator-(const big_decimal& other) const;
|
||||
big_decimal div(const ::uint64_t y, const rounding_mode mode) const;
|
||||
friend bool operator<(const big_decimal& x, const big_decimal& y) { return x.compare(y) < 0; }
|
||||
friend bool operator<=(const big_decimal& x, const big_decimal& y) { return x.compare(y) <= 0; }
|
||||
friend bool operator==(const big_decimal& x, const big_decimal& y) { return x.compare(y) == 0; }
|
||||
friend bool operator!=(const big_decimal& x, const big_decimal& y) { return x.compare(y) != 0; }
|
||||
friend bool operator>=(const big_decimal& x, const big_decimal& y) { return x.compare(y) >= 0; }
|
||||
friend bool operator>(const big_decimal& x, const big_decimal& y) { return x.compare(y) > 0; }
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
Reference in New Issue
Block a user