Replace qExchange with std::exchange

None of these users require C++20 constexpr or C++23 noexcept, the
only remaining difference between std::exchange and qExchange.

This leaves a single qExchange() user, in QScopedValueRollback, that
requires the constexpr version, only available from C++20, and thus
remains unported.

Task-number: QTBUG-99313
Change-Id: Iea46f6ed61d6bd8a5b2fd9d9ec4d70c980b443a2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-10-06 07:14:45 +02:00
parent e08fa9cc01
commit dd562b3672
8 changed files with 11 additions and 11 deletions

View File

@ -213,7 +213,7 @@ void DtlsServer::decryptDatagram(QDtls *connection, const QByteArray &clientMess
//! [14] //! [14]
void DtlsServer::shutdown() void DtlsServer::shutdown()
{ {
for (const auto &connection : qExchange(knownClients, {})) for (const auto &connection : std::exchange(knownClients, {}))
connection->shutdown(&serverSocket); connection->shutdown(&serverSocket);
serverSocket.close(); serverSocket.close();

View File

@ -92,7 +92,7 @@ public:
QAppleRefCounted(QAppleRefCounted &&other) QAppleRefCounted(QAppleRefCounted &&other)
noexcept(std::is_nothrow_move_assignable<T>::value && noexcept(std::is_nothrow_move_assignable<T>::value &&
std::is_nothrow_move_constructible<T>::value) std::is_nothrow_move_constructible<T>::value)
: value(qExchange(other.value, T())) {} : value(std::exchange(other.value, T())) {}
QAppleRefCounted(const QAppleRefCounted &other) : value(other.value) { if (value) RetainFunction(value); } QAppleRefCounted(const QAppleRefCounted &other) : value(other.value) { if (value) RetainFunction(value); }
~QAppleRefCounted() { if (value) ReleaseFunction(value); } ~QAppleRefCounted() { if (value) ReleaseFunction(value); }
operator T() const { return value; } operator T() const { return value; }
@ -258,7 +258,7 @@ public:
Q_DISABLE_COPY(QAppleLogActivity) Q_DISABLE_COPY(QAppleLogActivity)
QAppleLogActivity(QAppleLogActivity &&other) QAppleLogActivity(QAppleLogActivity &&other)
: activity(qExchange(other.activity, nullptr)), state(other.state) : activity(std::exchange(other.activity, nullptr)), state(other.state)
{ {
} }
@ -333,7 +333,7 @@ public:
QMacNotificationObserver(const QMacNotificationObserver &other) = delete; QMacNotificationObserver(const QMacNotificationObserver &other) = delete;
QMacNotificationObserver(QMacNotificationObserver &&other) QMacNotificationObserver(QMacNotificationObserver &&other)
: observer(qExchange(other.observer, nullptr)) : observer(std::exchange(other.observer, nullptr))
{ {
} }

View File

@ -34,7 +34,7 @@ public:
~QWinRegistryKey(); ~QWinRegistryKey();
QWinRegistryKey(QWinRegistryKey &&other) noexcept QWinRegistryKey(QWinRegistryKey &&other) noexcept
: m_key(qExchange(other.m_key, nullptr)) {} : m_key(std::exchange(other.m_key, nullptr)) {}
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QWinRegistryKey) QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QWinRegistryKey)
void swap(QWinRegistryKey &other) noexcept { qSwap(m_key, other.m_key); } void swap(QWinRegistryKey &other) noexcept { qSwap(m_key, other.m_key); }

View File

@ -56,13 +56,13 @@ class QDuplicateTracker {
auto insert(const T &e) { auto insert(const T &e) {
auto it = QSet<T>::insert(e); auto it = QSet<T>::insert(e);
const auto n = this->size(); const auto n = this->size();
return std::pair{it, qExchange(setSize, n) != n}; return std::pair{it, std::exchange(setSize, n) != n};
} }
auto insert(T &&e) { auto insert(T &&e) {
auto it = QSet<T>::insert(std::move(e)); auto it = QSet<T>::insert(std::move(e));
const auto n = this->size(); const auto n = this->size();
return std::pair{it, qExchange(setSize, n) != n}; return std::pair{it, std::exchange(setSize, n) != n};
} }
}; };
Set set{Prealloc}; Set set{Prealloc};

View File

@ -49,7 +49,7 @@ public:
const T *data() const noexcept { return d; } const T *data() const noexcept { return d; }
const T *get() const noexcept { return d; } const T *get() const noexcept { return d; }
const T *constData() const noexcept { return d; } const T *constData() const noexcept { return d; }
T *take() noexcept { return qExchange(d, nullptr); } T *take() noexcept { return std::exchange(d, nullptr); }
QSharedDataPointer() noexcept : d(nullptr) { } QSharedDataPointer() noexcept : d(nullptr) { }
~QSharedDataPointer() { if (d && !d->ref.deref()) delete d; } ~QSharedDataPointer() { if (d && !d->ref.deref()) delete d; }

View File

@ -92,7 +92,7 @@ public:
constexpr T *take() noexcept constexpr T *take() noexcept
{ {
return qExchange(d, nullptr); return std::exchange(d, nullptr);
} }
bool isShared() const noexcept bool isShared() const noexcept

View File

@ -988,7 +988,7 @@ void QWidgetRepaintManager::flush()
if (!hasNeedsFlushWidgets) if (!hasNeedsFlushWidgets)
return; return;
for (QWidget *w : qExchange(needsFlushWidgets, {})) { for (QWidget *w : std::exchange(needsFlushWidgets, {})) {
QWidgetPrivate *wd = w->d_func(); QWidgetPrivate *wd = w->d_func();
Q_ASSERT(wd->needsFlush); Q_ASSERT(wd->needsFlush);
QPlatformTextureList *widgetTexturesForNative = wd->textureChildSeen ? widgetTexturesFor(tlw, w) : nullptr; QPlatformTextureList *widgetTexturesForNative = wd->textureChildSeen ? widgetTexturesFor(tlw, w) : nullptr;

View File

@ -5513,7 +5513,7 @@ public:
} }
QObjectCastChecker(QObjectCastChecker &&other) noexcept QObjectCastChecker(QObjectCastChecker &&other) noexcept
: m_target(qExchange(other.m_target, nullptr)) : m_target(std::exchange(other.m_target, nullptr))
{} {}
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QObjectCastChecker) QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QObjectCastChecker)