From 889d40ebe2d9d0e92caea2749608720f7c088173 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 3 Jan 2020 17:18:02 +0100 Subject: Centralize the implementation of move assignment operators At the moment we have two main strategies for dealing with move assignment in Qt: 1) move-and-swap, used by "containers" (in the broad sense): containers, but also smart pointers and similar classes that can hold user-defined types; 2) pure swap, used by containers that hold only memory (e.g. QString, QByteArray, ...) as well as most implicitly shared datatypes. Given the fact that a move assignment operator's code is just boilerplate (whether it's move-and-swap or pure swap), provide two _strictly internal_ macros to help write them, and apply the macros across corelib and gui, porting away from the hand-rolled implementations. The rule of thumb when porting to the new macros is: * Try to stick to the existing code behavior, unless broken * if changing, then follow this checklist: * if the class does not have a move constructor => pure swap (but consider ADDING a move constructor, if possible!) * if the class does have a move constructor, try to follow the criteria above, namely: * if the class holds only memory, pure swap; * if the class may hold anything else but memory (file handles, etc.), then move and swap. Noteworthy details: * some operators planned to be removed in Qt 6 were not ported; * as drive-by, some move constructors were simplified to be using qExchange(); others were outright broken and got fixed; * some contained some more interesting code and were not touched. Change-Id: Idaab3489247dcbabb6df3fa1e5286b69e1d372e9 Reviewed-by: Allan Sandfeld Jensen --- src/gui/text/qfontmetrics.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/gui/text/qfontmetrics.h') diff --git a/src/gui/text/qfontmetrics.h b/src/gui/text/qfontmetrics.h index 097d40bf8d..a199e20373 100644 --- a/src/gui/text/qfontmetrics.h +++ b/src/gui/text/qfontmetrics.h @@ -60,8 +60,7 @@ public: ~QFontMetrics(); QFontMetrics &operator=(const QFontMetrics &); - inline QFontMetrics &operator=(QFontMetrics &&other) noexcept - { qSwap(d, other.d); return *this; } + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFontMetrics) void swap(QFontMetrics &other) noexcept { qSwap(d, other.d); } @@ -131,8 +130,7 @@ public: QFontMetricsF &operator=(const QFontMetricsF &); QFontMetricsF &operator=(const QFontMetrics &); - inline QFontMetricsF &operator=(QFontMetricsF &&other) noexcept - { qSwap(d, other.d); return *this; } + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFontMetricsF) void swap(QFontMetricsF &other) noexcept { qSwap(d, other.d); } -- cgit v1.2.3