diff options
author | Luca Di Sera <luca.disera@qt.io> | 2022-03-17 11:22:44 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-03-18 20:56:19 +0000 |
commit | 33d62de7c88551218124c8d7c91736366720a849 (patch) | |
tree | 13c3c63653ba6a7b1e00d01222bc99db5ab1da64 /src/corelib/io/qtemporarydir.cpp | |
parent | e14466aa66406da46da5dc70f94529ccfe6fb911 (diff) |
Enable move semantics for QTemporaryDir
Add move constructor and move assignment operator.
To allow for the the change to be implemented QTemporaryDir, the
internal d_ptr was modified from a QScopedPointer, which is not movable,
to a raw pointer.
Add member + free swap implementations.
Add tests.
[ChangeLog][QtCore][QTemporaryDir] Enabled move semantics.
Change-Id: I9f196a77c70b4ca0b7f0c06505d00fdd87a9785c
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/io/qtemporarydir.cpp')
-rw-r--r-- | src/corelib/io/qtemporarydir.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/corelib/io/qtemporarydir.cpp b/src/corelib/io/qtemporarydir.cpp index db35256704..c9573182c4 100644 --- a/src/corelib/io/qtemporarydir.cpp +++ b/src/corelib/io/qtemporarydir.cpp @@ -57,8 +57,13 @@ #include <errno.h> #endif +#include <type_traits> + QT_BEGIN_NAMESPACE +static_assert(std::is_nothrow_move_constructible_v<QTemporaryDir>); +static_assert(std::is_nothrow_move_assignable_v<QTemporaryDir>); + //************* QTemporaryDirPrivate class QTemporaryDirPrivate { @@ -198,6 +203,39 @@ QTemporaryDir::QTemporaryDir(const QString &templatePath) } /*! + \fn QTemporaryDir::QTemporaryDir(QTemporaryDir &&other) + + Move-constructs a new QTemporaryDir from \a other. + + \note The moved-from object \a other is placed in a + partially-formed state, in which the only valid operations are + destruction and assignment of a new value. + + \since 6.4 +*/ + +/*! + \fn QTemporaryDir &QTemporaryDir::operator=(QTemporaryDir&& other) + + Move-assigns \a other to this QTemporaryDir instance. + + \note The moved-from object \a other is placed in a + partially-formed state, in which the only valid operations are + destruction and assignment of a new value. + + \since 6.4 +*/ + +/*! + \fn void QTemporaryDir::swap(QTemporaryDir &other) + + Swaps temporary-dir \a other with this temporary-dir. This operation is + very fast and never fails. + + \since 6.4 +*/ + +/*! Destroys the temporary directory object. If auto remove mode was set, it will automatically delete the directory including all its contents. @@ -206,8 +244,12 @@ QTemporaryDir::QTemporaryDir(const QString &templatePath) */ QTemporaryDir::~QTemporaryDir() { - if (d_ptr->autoRemove) - remove(); + if (d_ptr) { + if (d_ptr->autoRemove) + remove(); + + delete d_ptr; + } } /*! |