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>
This commit is contained in:
Marc Mutz 2022-12-05 11:12:55 +01:00
parent c262a1805a
commit e1b76ee928
3 changed files with 7 additions and 1 deletions

View File

@ -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)

View File

@ -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`.)

View File

@ -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