diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index ceb4553b635..d3f757148d7 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -114,6 +114,14 @@ namespace QtSharedPointer { void destroy() { destroyer(this); } + bool isShared() const noexcept { + return strongref.loadRelaxed() != 1; + } + + bool needsDetach() const noexcept { + return strongref.loadRelaxed() > 1; + } + #ifndef QT_NO_QOBJECT Q_CORE_EXPORT static ExternalRefCountData *getAndRef(const QObject *); QT6_ONLY( @@ -463,6 +471,11 @@ template class QSharedPointer size_t owner_hash() const noexcept { return std::hash()(d); } + bool isShared() const noexcept + { return !d || d->isShared(); } + bool needsDetach() const noexcept + { return !d || d->needsDetach(); } + private: Q_NODISCARD_CTOR explicit QSharedPointer(Qt::Initialization) {} @@ -717,6 +730,11 @@ class QWeakPointer size_t owner_hash() const noexcept { return std::hash()(d); } + bool isShared() const noexcept + { return !d || d->isShared(); } + bool needsDetach() const noexcept + { return !d || d->needsDetach(); } + private: friend struct QtPrivate::EnableInternalData; template friend class QSharedPointer;