diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-01-03 17:18:02 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-03 11:47:17 +0200 |
commit | 889d40ebe2d9d0e92caea2749608720f7c088173 (patch) | |
tree | a68214fbf5a0dc9b1488e4ae79a499dabc1cc445 /src/opengl | |
parent | 990e2e4fb8ef546b89b5e83e659771edd5b4ed3e (diff) |
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 <allan.jensen@qt.io>
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/qopengldebug.h | 2 | ||||
-rw-r--r-- | src/opengl/qopenglpixeltransferoptions.h | 3 |
2 files changed, 2 insertions, 3 deletions
diff --git a/src/opengl/qopengldebug.h b/src/opengl/qopengldebug.h index c12d996493..f61808e4c7 100644 --- a/src/opengl/qopengldebug.h +++ b/src/opengl/qopengldebug.h @@ -109,7 +109,7 @@ public: QOpenGLDebugMessage(const QOpenGLDebugMessage &debugMessage); QOpenGLDebugMessage &operator=(const QOpenGLDebugMessage &debugMessage); - QOpenGLDebugMessage &operator=(QOpenGLDebugMessage &&other) noexcept { swap(other); return *this; } + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QOpenGLDebugMessage) ~QOpenGLDebugMessage(); void swap(QOpenGLDebugMessage &other) noexcept { qSwap(d, other.d); } diff --git a/src/opengl/qopenglpixeltransferoptions.h b/src/opengl/qopenglpixeltransferoptions.h index 252c2a2f1e..1f9c1eb9db 100644 --- a/src/opengl/qopenglpixeltransferoptions.h +++ b/src/opengl/qopenglpixeltransferoptions.h @@ -55,8 +55,7 @@ class Q_OPENGL_EXPORT QOpenGLPixelTransferOptions public: QOpenGLPixelTransferOptions(); QOpenGLPixelTransferOptions(const QOpenGLPixelTransferOptions &); - QOpenGLPixelTransferOptions &operator=(QOpenGLPixelTransferOptions &&other) noexcept - { swap(other); return *this; } + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QOpenGLPixelTransferOptions) QOpenGLPixelTransferOptions &operator=(const QOpenGLPixelTransferOptions &); ~QOpenGLPixelTransferOptions(); |