From c441e2cc476c76496f037f0b5f4bd4bfdd82c727 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 2 Oct 2020 17:38:40 +0200 Subject: [PATCH] QMacKeyValueObserver: code tidies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the constructors and the signature of swap(). Change-Id: Ib294bb2c054510170b166b5c8bd3180d22177efc Reviewed-by: Tor Arne Vestbø --- src/corelib/kernel/qcore_mac_p.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index 02ea0aabdc..cb00fe0b24 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -367,7 +367,7 @@ class Q_CORE_EXPORT QMacKeyValueObserver public: using Callback = std::function; - QMacKeyValueObserver() {} + QMacKeyValueObserver() = default; #if defined( __OBJC__) // Note: QMacKeyValueObserver must not outlive the object observed! @@ -381,13 +381,13 @@ public: QMacKeyValueObserver(const QMacKeyValueObserver &other); - QMacKeyValueObserver(QMacKeyValueObserver &&other) { swap(other, *this); } + QMacKeyValueObserver(QMacKeyValueObserver &&other) noexcept { swap(other); } ~QMacKeyValueObserver() { removeObserver(); } QMacKeyValueObserver &operator=(const QMacKeyValueObserver &other) { QMacKeyValueObserver tmp(other); - swap(tmp, *this); + swap(tmp); return *this; } @@ -399,13 +399,14 @@ public: void removeObserver(); -private: - void swap(QMacKeyValueObserver &first, QMacKeyValueObserver &second) { - std::swap(first.object, second.object); - std::swap(first.keyPath, second.keyPath); - std::swap(first.callback, second.callback); + void swap(QMacKeyValueObserver &other) noexcept + { + qSwap(object, other.object); + qSwap(keyPath, other.keyPath); + qSwap(callback, other.callback); } +private: #if defined( __OBJC__) void addObserver(NSKeyValueObservingOptions options); #endif