From d5db58127b16f3c2508975661ee7328f569b9518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 6 Nov 2009 16:09:39 +0100 Subject: Make QScopedPointer::operator== and != non-member Non-member operator allows implicit conversions on both arguments. A single operator is enough to support QScopedArrayPointer, QCustomScopedPointer and QScopedSharedPointer since equality semantics don't change and the deleter is managed in the base class. Reviewed-by: Marius Storm-Olsen --- src/corelib/tools/qscopedpointer.h | 52 +++++++++----------------------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index 7cbdb6c..b433723 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -113,16 +113,6 @@ public: return d; } - inline bool operator==(const QScopedPointer &other) const - { - return d == other.d; - } - - inline bool operator!=(const QScopedPointer &other) const - { - return d != other.d; - } - inline bool operator!() const { return !d; @@ -181,6 +171,18 @@ private: }; template +inline bool operator==(const QScopedPointer &lhs, const QScopedPointer &rhs) +{ + return lhs.data() == rhs.data(); +} + +template +inline bool operator!=(const QScopedPointer &lhs, const QScopedPointer &rhs) +{ + return lhs.data() != rhs.data(); +} + +template Q_INLINE_TEMPLATE void qSwap(QScopedPointer &p1, QScopedPointer &p2) { p1.swap(p2); } @@ -203,16 +205,6 @@ public: return this->d[i]; } - inline bool operator==(const QScopedArrayPointer &other) const - { - return this->d == other.d; - } - - inline bool operator!=(const QScopedArrayPointer &other) const - { - return this->d != other.d; - } - private: Q_DISABLE_COPY(QScopedArrayPointer) }; @@ -233,16 +225,6 @@ public: return this->d; } - inline bool operator==(const QCustomScopedPointer &other) const - { - return this->d == other.d; - } - - inline bool operator!=(const QCustomScopedPointer &other) const - { - return this->d != other.d; - } - private: Q_DISABLE_COPY(QCustomScopedPointer) }; @@ -287,16 +269,6 @@ public: QScopedPointerSharedDeleter::cleanup(oldD); } - inline bool operator==(const QScopedSharedPointer &other) const - { - return this->d == other.d; - } - - inline bool operator!=(const QScopedSharedPointer &other) const - { - return this->d != other.d; - } - private: Q_DISABLE_COPY(QScopedSharedPointer) }; -- cgit v0.12