From 358745d7ded0492cc8c61fa46d7c0928f584c184 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 24 Oct 2023 21:13:36 +0200 Subject: QSP/QWP: introduce owner_before, owner_equal, owner_hash While at the moment we don't have aliasing support in QSharedPointer, introduce owner-based comparisons and hashing. This also fulfills some use cases in lieu of operator== for QWeakPointer (which got deprecated by bb23a05905d7dc0e416a646e40592436daa939f2). I'm using C++26/P1901's spelling of owner_equal, instead of Boost.SmartPtr's spelling (owner_equal*s*). Given the niche use case, the lack of interoperability with Qt's own containers, as well as the Standard comparison objects' semantics (std::owner_less, std::owner_equal), I don't think we should be giving these a Qt-ish name as it would be pretty useless. [ChangeLog][QtCore][QSharedPointer] Added owner_before, owner_equal, owner_hash. [ChangeLog][QtCore][QWeakPointer] Added owner_before, owner_equal, owner_hash. Done-with: Fabian Kosmale Change-Id: I8b792ae79f14cd518ba4a006edaa17786a8352a0 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- src/corelib/tools/qsharedpointer.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/corelib/tools/qsharedpointer.h') diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index 2a60f3ca5e..116c9afa00 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -72,6 +72,19 @@ public: template static inline QSharedPointer create(Args &&... args); + + // owner-based comparisons + template + bool owner_before(const QSharedPointer &other) const noexcept; + template + bool owner_before(const QWeakPointer &other) const noexcept; + + template + bool owner_equal(const QSharedPointer &other) const noexcept; + template + bool owner_equal(const QWeakPointer &other) const noexcept; + + size_t owner_hash() const noexcept; }; template @@ -108,6 +121,19 @@ public: QSharedPointer toStrongRef() const; QSharedPointer lock() const; + + // owner-based comparisons + template + bool owner_before(const QWeakPointer &other) const noexcept; + template + bool owner_before(const QSharedPointer &other) const noexcept; + + template + bool owner_equal(const QWeakPointer &other) const noexcept; + template + bool owner_equal(const QSharedPointer &other) const noexcept; + + size_t owner_hash() const noexcept; }; template -- cgit v1.2.3