summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-12-05 11:12:55 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-12-14 19:07:19 +0100
commite1b76ee928beff434d220c7711ea6798318d367e (patch)
treeed71e360161a78a2586bc8351656c2f672c09796
parentc262a1805a062fd99abc890f58ea951da80ff0af (diff)
Remove the last in-tree user of qExchange() and mark all of Qt free of it
We've ported all qExchange() to std::exchange by now, across all modules, but the one in QScopedValueRollback was left behind, because it requires C++20's version of std::exchange (constexpr). Since q20::exchange was not approved, replace the qExchange() here with two moves and add a comment to port to std::exchange() once we can depend on C++20. Then add QT_NO_QEXCHANGE to avoid new uses from creeping in. Change-Id: I488e252433e78fb2766639dbe77a22a55196cfd1 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--cmake/QtInternalTargets.cmake1
-rw-r--r--src/corelib/global/qttypetraits.h4
-rw-r--r--src/corelib/tools/qscopedvaluerollback.h3
3 files changed, 7 insertions, 1 deletions
diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake
index dc45b57eec..8de5f8a080 100644
--- a/cmake/QtInternalTargets.cmake
+++ b/cmake/QtInternalTargets.cmake
@@ -151,6 +151,7 @@ qt_internal_add_target_aliases(PlatformToolInternal)
target_link_libraries(PlatformToolInternal INTERFACE PlatformAppInternal)
qt_internal_add_global_definition(QT_NO_JAVA_STYLE_ITERATORS)
+qt_internal_add_global_definition(QT_NO_QEXCHANGE)
qt_internal_add_global_definition(QT_NO_NARROWING_CONVERSIONS_IN_CONNECT)
qt_internal_add_global_definition(QT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH)
diff --git a/src/corelib/global/qttypetraits.h b/src/corelib/global/qttypetraits.h
index 7e991ab8ca..a7bb4e5353 100644
--- a/src/corelib/global/qttypetraits.h
+++ b/src/corelib/global/qttypetraits.h
@@ -34,6 +34,8 @@ void qAsConst(const T &&) = delete;
#endif // QT_NO_AS_CONST
+#ifndef QT_NO_QEXCHANGE
+
// like std::exchange
template <typename T, typename U = T>
constexpr T qExchange(T &t, U &&newValue)
@@ -45,6 +47,8 @@ noexcept(std::conjunction_v<std::is_nothrow_move_constructible<T>,
return old;
}
+#endif // QT_NO_QEXCHANGE
+
namespace QtPrivate {
// helper to be used to trigger a "dependent static_assert(false)"
// (for instance, in a final `else` branch of a `if constexpr`.)
diff --git a/src/corelib/tools/qscopedvaluerollback.h b/src/corelib/tools/qscopedvaluerollback.h
index a4a451b0c7..53a31e4675 100644
--- a/src/corelib/tools/qscopedvaluerollback.h
+++ b/src/corelib/tools/qscopedvaluerollback.h
@@ -18,8 +18,9 @@ public:
}
explicit constexpr QScopedValueRollback(T &var, T value)
- : varRef(var), oldValue(qExchange(var, std::move(value)))
+ : varRef(var), oldValue(std::move(var)) // ### C++20: std::exchange(var, std::move(value))
{
+ var = std::move(value);
}
#if __cpp_constexpr >= 201907L