diff options
Diffstat (limited to 'src/corelib/tools/qscopedpointer.h')
-rw-r--r-- | src/corelib/tools/qscopedpointer.h | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index 3e6af97a33..92d7df6e5d 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -97,7 +97,7 @@ class QScopedPointer { typedef T *QScopedPointer:: *RestrictedBool; public: - explicit inline QScopedPointer(T *p = Q_NULLPTR) : d(p) + explicit QScopedPointer(T *p = Q_NULLPTR) Q_DECL_NOTHROW : d(p) { } @@ -113,13 +113,12 @@ public: return *d; } - inline T *operator->() const + T *operator->() const Q_DECL_NOTHROW { - Q_ASSERT(d); return d; } - inline bool operator!() const + bool operator!() const Q_DECL_NOTHROW { return !d; } @@ -130,23 +129,23 @@ public: return isNull() ? Q_NULLPTR : &QScopedPointer::d; } #else - inline operator RestrictedBool() const + operator RestrictedBool() const Q_DECL_NOTHROW { return isNull() ? Q_NULLPTR : &QScopedPointer::d; } #endif - inline T *data() const + T *data() const Q_DECL_NOTHROW { return d; } - inline bool isNull() const + bool isNull() const Q_DECL_NOTHROW { return !d; } - inline void reset(T *other = Q_NULLPTR) + void reset(T *other = Q_NULLPTR) Q_DECL_NOEXCEPT_EXPR(noexcept(Cleanup::cleanup(std::declval<T *>()))) { if (d == other) return; @@ -155,7 +154,7 @@ public: Cleanup::cleanup(oldD); } - inline T *take() + T *take() Q_DECL_NOTHROW { T *oldD = d; d = Q_NULLPTR; @@ -177,18 +176,42 @@ private: }; template <class T, class Cleanup> -inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) +inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW { return lhs.data() == rhs.data(); } template <class T, class Cleanup> -inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) +inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW { return lhs.data() != rhs.data(); } template <class T, class Cleanup> +inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t) Q_DECL_NOTHROW +{ + return lhs.isNull(); +} + +template <class T, class Cleanup> +inline bool operator==(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW +{ + return rhs.isNull(); +} + +template <class T, class Cleanup> +inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t) Q_DECL_NOTHROW +{ + return !lhs.isNull(); +} + +template <class T, class Cleanup> +inline bool operator!=(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW +{ + return !rhs.isNull(); +} + +template <class T, class Cleanup> inline void swap(QScopedPointer<T, Cleanup> &p1, QScopedPointer<T, Cleanup> &p2) Q_DECL_NOTHROW { p1.swap(p2); } |