From ec0c62385e0df00f42bc9fb5e117cb8b994cfc96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8ger=20Hanseg=C3=A5rd?= Date: Thu, 2 Jan 2025 10:46:59 +0100 Subject: [PATCH] Implement QUniqueHandle::release() using std::exchange This does not change the behavior of release() but gives more compact code. Task-number: QTBUG-132507 Pick-to: 6.8 6.9 Change-Id: I5b34c80409ca0e9e9a5e9aee9ef7bc80017610af Reviewed-by: Thiago Macieira --- src/corelib/tools/quniquehandle_p.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/quniquehandle_p.h b/src/corelib/tools/quniquehandle_p.h index 881dea07ba3..d388b1bb0fc 100644 --- a/src/corelib/tools/quniquehandle_p.h +++ b/src/corelib/tools/quniquehandle_p.h @@ -19,6 +19,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -162,9 +163,7 @@ public: [[nodiscard]] Type release() noexcept { - Type handle = m_handle; - m_handle = HandleTraits::invalidValue(); - return handle; + return std::exchange(m_handle, HandleTraits::invalidValue()); } [[nodiscard]] Type *operator&() noexcept // NOLINT(google-runtime-operator)