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 <thiago.macieira@intel.com>
This commit is contained in:
Jøger Hansegård 2025-01-02 10:46:59 +01:00
parent 248ac4128f
commit ec0c62385e

View File

@ -19,6 +19,7 @@
#include <QtCore/qassert.h>
#include <memory>
#include <utility>
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)