From 358248b4950131711ae408da9aa30d41c5143e4f Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 10 Sep 2022 19:40:51 +0200 Subject: Make QCryptographicHash move constructible This adds a move constructor, a move assignment operator and a swap function to QCryptographicHash. This can (to name one example) be useful when you want to store multiple hashes in a vector. [ChangeLog][QtCore][QCryptographicHash] Added move constructor, move assignment operator and swap() function. Change-Id: Id54594fa69104ec25ad78581f962a021e85531c2 Reviewed-by: Marc Mutz --- src/corelib/tools/qcryptographichash.cpp | 33 ++++++++++++++++++++++++++++++++ src/corelib/tools/qcryptographichash.h | 4 ++++ 2 files changed, 37 insertions(+) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 8d60be175e..3f6075f2aa 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -315,6 +315,18 @@ QCryptographicHash::QCryptographicHash(Algorithm method) { } +/*! + \fn QCryptographicHash::QCryptographicHash(QCryptographicHash &&other) + + Move-constructs a new QCryptographicHash 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.5 +*/ + /*! Destroys the object. */ @@ -323,6 +335,27 @@ QCryptographicHash::~QCryptographicHash() delete d; } +/*! + \fn QCryptographicHash &QCryptographicHash::operator=(QCryptographicHash &&other) + + Move-assigns \a other to this QCryptographicHash 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.5 +*/ + +/*! + \fn void QCryptographicHash::swap(QCryptographicHash &other) + + Swaps cryptographic hash \a other with this cryptographic hash. This + operation is very fast and never fails. + + \since 6.5 +*/ + /*! Resets the object. */ diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h index f5710015cf..94fc82783b 100644 --- a/src/corelib/tools/qcryptographichash.h +++ b/src/corelib/tools/qcryptographichash.h @@ -64,8 +64,12 @@ public: Q_ENUM(Algorithm) explicit QCryptographicHash(Algorithm method); + QCryptographicHash(QCryptographicHash &&other) noexcept : d(std::exchange(other.d, nullptr)) {} ~QCryptographicHash(); + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCryptographicHash) + void swap(QCryptographicHash &other) noexcept { qt_ptr_swap(d, other.d); } + void reset() noexcept; #if QT_DEPRECATED_SINCE(6, 4) -- cgit v1.2.3