diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-05-13 20:43:27 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-05-14 17:21:40 +0000 |
commit | a73385e2cfd0455f09166cdb380876ba8b26fb5f (patch) | |
tree | 02d837ce2b268089d7f8676b98a9db27ed6dcb58 /src/corelib/global/qglobal.h | |
parent | 969e60e075b2560f499b7a98b502401a23c8c319 (diff) |
Short live qExchange()!
This is a 1:1 replacement for std::exchange, and should be removed once
Qt fully depends on C++14. It's too versatile a tool to miss it, so
provide a copy.
[ChangeLog][QtCore][QtGlobal] Added qExchange(), a drop-in for C++14's std::exchange()
Change-Id: I31c4f1141e7a99f99ea65eb36ddf9d68b7847337
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qglobal.h')
-rw-r--r-- | src/corelib/global/qglobal.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 0a0c434a07..24d250d923 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1008,6 +1008,15 @@ Q_DECL_CONSTEXPR typename std::add_const<T>::type &qAsConst(T &t) noexcept { ret template <typename T> void qAsConst(const T &&) = delete; +// like std::exchange +template <typename T, typename U = T> +Q_DECL_RELAXED_CONSTEXPR T qExchange(T &t, U &&newValue) +{ + T old = std::move(t); + t = std::forward<U>(newValue); + return old; +} + #ifndef QT_NO_FOREACH namespace QtPrivate { |