QPointer: add member-swap
Change-Id: I5704badc86f98e549c586656ec8df3915632ce15 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
9f1646b0d9
commit
2d9700c041
@ -127,6 +127,14 @@
|
||||
pointed to.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QPointer::swap(QPointer<T> &other)
|
||||
\since 5.6
|
||||
|
||||
Swaps the contents of this QPointer with the contents of \a other.
|
||||
This operation is very fast and never fails.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QPointer<T> & QPointer::operator=(T* p)
|
||||
|
||||
|
@ -66,6 +66,8 @@ public:
|
||||
// compiler-generated copy/move ctor/assignment operators are fine!
|
||||
inline ~QPointer() { }
|
||||
|
||||
inline void swap(QPointer &other) { wp.swap(other.wp); }
|
||||
|
||||
inline QPointer<T> &operator=(T* p)
|
||||
{ wp.assign(static_cast<QObjectType*>(p)); return *this; }
|
||||
|
||||
|
@ -50,6 +50,7 @@ private slots:
|
||||
void destructor();
|
||||
void assignment_operators();
|
||||
void equality_operators();
|
||||
void swap();
|
||||
void isNull();
|
||||
void dereference_operators();
|
||||
void disconnect();
|
||||
@ -169,6 +170,22 @@ void tst_QPointer::equality_operators()
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QPointer::swap()
|
||||
{
|
||||
QPointer<QObject> c1, c2;
|
||||
{
|
||||
QObject o;
|
||||
c1 = &o;
|
||||
QVERIFY(c2.isNull());
|
||||
QCOMPARE(c1.data(), &o);
|
||||
c1.swap(c2);
|
||||
QVERIFY(c1.isNull());
|
||||
QCOMPARE(c2.data(), &o);
|
||||
}
|
||||
QVERIFY(c1.isNull());
|
||||
QVERIFY(c2.isNull());
|
||||
}
|
||||
|
||||
void tst_QPointer::isNull()
|
||||
{
|
||||
QPointer<QObject> p1;
|
||||
|
Loading…
Reference in New Issue
Block a user