From: Kefu Chai Date: Wed, 3 Aug 2022 03:40:50 +0000 (+0800) Subject: common: drop WRITE_{EQ,CMP}_OPERATORS_7() X-Git-Tag: v18.0.0~339^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e9963ed7dc6959eb64086457a7f8339036172435;p=ceph-ci.git common: drop WRITE_{EQ,CMP}_OPERATORS_7() the default-generated comparison operators can fulfill our needs. Signed-off-by: Kefu Chai --- diff --git a/src/common/hobject.h b/src/common/hobject.h index 07a23daa511..83885163efe 100644 --- a/src/common/hobject.h +++ b/src/common/hobject.h @@ -305,20 +305,26 @@ public: void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list& o); friend int cmp(const hobject_t& l, const hobject_t& r); - friend bool operator>(const hobject_t& l, const hobject_t& r) { - return cmp(l, r) > 0; - } - friend bool operator>=(const hobject_t& l, const hobject_t& r) { - return cmp(l, r) >= 0; - } - friend bool operator<(const hobject_t& l, const hobject_t& r) { - return cmp(l, r) < 0; + auto operator<=>(const hobject_t &rhs) const noexcept { + auto cmp = max <=> rhs.max; + if (cmp != 0) return cmp; + cmp = pool <=> rhs.pool; + if (cmp != 0) return cmp; + cmp = get_bitwise_key() <=> rhs.get_bitwise_key(); + if (cmp != 0) return cmp; + cmp = nspace <=> rhs.nspace; + if (cmp != 0) return cmp; + if (!(get_key().empty() && rhs.get_key().empty())) { + cmp = get_effective_key() <=> rhs.get_effective_key(); + if (cmp != 0) return cmp; + } + cmp = oid <=> rhs.oid; + if (cmp != 0) return cmp; + return snap <=> rhs.snap; } - friend bool operator<=(const hobject_t& l, const hobject_t& r) { - return cmp(l, r) <= 0; + bool operator==(const hobject_t& rhs) const noexcept { + return operator<=>(rhs) == 0; } - friend bool operator==(const hobject_t&, const hobject_t&); - friend bool operator!=(const hobject_t&, const hobject_t&); friend struct ghobject_t; }; WRITE_CLASS_ENCODER(hobject_t) @@ -334,8 +340,6 @@ template<> struct hash { std::ostream& operator<<(std::ostream& out, const hobject_t& o); -WRITE_EQ_OPERATORS_7(hobject_t, hash, oid, get_key(), snap, pool, max, nspace) - template struct always_false { using value = std::false_type;