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 constexpr T qExchange(T &t, U &&newValue) @@ -45,6 +47,8 @@ noexcept(std::conjunction_v, 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