diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp index 7647916e99e..b0673920714 100644 --- a/src/corelib/tools/qscopedpointer.cpp +++ b/src/corelib/tools/qscopedpointer.cpp @@ -183,21 +183,20 @@ QT_BEGIN_NAMESPACE */ /*! - \fn template bool operator==(const QScopedPointer &lhs, const QScopedPointer &rhs) + \fn template bool QScopedPointer::operator==(const QScopedPointer &lhs, const QScopedPointer &rhs) - Returns \c true if \a ptr1 and \a ptr2 refer to the same pointer. + Returns \c true if \a lhs and \a rhs refer to the same pointer. */ /*! - \fn template bool operator!=(const QScopedPointer &lhs, const QScopedPointer &rhs) + \fn template bool QScopedPointer::operator!=(const QScopedPointer &lhs, const QScopedPointer &rhs) Returns \c true if \a lhs and \a rhs refer to distinct pointers. */ /*! - \fn template bool operator==(const QScopedPointer &lhs, std::nullptr_t) - \relates QScopedPointer + \fn template bool QScopedPointer::operator==(const QScopedPointer &lhs, std::nullptr_t) \since 5.8 Returns \c true if \a lhs refers to \nullptr. @@ -206,8 +205,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn template bool operator==(std::nullptr_t, const QScopedPointer &rhs) - \relates QScopedPointer + \fn template bool QScopedPointer::operator==(std::nullptr_t, const QScopedPointer &rhs) \since 5.8 Returns \c true if \a rhs refers to \nullptr. @@ -216,8 +214,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn template bool operator!=(const QScopedPointer &lhs, std::nullptr_t) - \relates QScopedPointer + \fn template bool QScopedPointer::operator!=(const QScopedPointer &lhs, std::nullptr_t) \since 5.8 Returns \c true if \a lhs refers to a valid (i.e. non-null) pointer. @@ -226,8 +223,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn template bool operator!=(std::nullptr_t, const QScopedPointer &rhs) - \relates QScopedPointer + \fn template bool QScopedPointer::operator!=(std::nullptr_t, const QScopedPointer &rhs) \since 5.8 Returns \c true if \a rhs refers to a valid (i.e. non-null) pointer. @@ -268,8 +264,8 @@ QT_BEGIN_NAMESPACE \sa isNull() */ -/*! \fn template void QScopedPointer::swap(QScopedPointer &other) - Swap this pointer with \a other. +/*! \fn template void QScopedPointer::swap(QScopedPointer &lhs, QScopedPointer &rhs) + Swaps \a lhs with \a rhs. */ /*! diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index 9f18e76c045..5b2a15f5f6d 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -165,6 +165,39 @@ public: typedef T *pointer; + friend bool operator==(const QScopedPointer &lhs, const QScopedPointer &rhs) noexcept + { + return lhs.data() == rhs.data(); + } + + friend bool operator!=(const QScopedPointer &lhs, const QScopedPointer &rhs) noexcept + { + return lhs.data() != rhs.data(); + } + + friend bool operator==(const QScopedPointer &lhs, std::nullptr_t) noexcept + { + return lhs.isNull(); + } + + friend bool operator==(std::nullptr_t, const QScopedPointer &rhs) noexcept + { + return rhs.isNull(); + } + + friend bool operator!=(const QScopedPointer &lhs, std::nullptr_t) noexcept + { + return !lhs.isNull(); + } + + friend bool operator!=(std::nullptr_t, const QScopedPointer &rhs) noexcept + { + return !rhs.isNull(); + } + + friend void swap(QScopedPointer &p1, QScopedPointer &p2) noexcept + { p1.swap(p2); } + protected: T *d; @@ -172,46 +205,6 @@ private: Q_DISABLE_COPY(QScopedPointer) }; -template -inline bool operator==(const QScopedPointer &lhs, const QScopedPointer &rhs) noexcept -{ - return lhs.data() == rhs.data(); -} - -template -inline bool operator!=(const QScopedPointer &lhs, const QScopedPointer &rhs) noexcept -{ - return lhs.data() != rhs.data(); -} - -template -inline bool operator==(const QScopedPointer &lhs, std::nullptr_t) noexcept -{ - return lhs.isNull(); -} - -template -inline bool operator==(std::nullptr_t, const QScopedPointer &rhs) noexcept -{ - return rhs.isNull(); -} - -template -inline bool operator!=(const QScopedPointer &lhs, std::nullptr_t) noexcept -{ - return !lhs.isNull(); -} - -template -inline bool operator!=(std::nullptr_t, const QScopedPointer &rhs) noexcept -{ - return !rhs.isNull(); -} - -template -inline void swap(QScopedPointer &p1, QScopedPointer &p2) noexcept -{ p1.swap(p2); } - template > class QScopedArrayPointer : public QScopedPointer {