Add a conditional noexcept specification to qExchange

Following P2401 (which libstdc++ and MS-STL already implement)
and [res.on.exception.handling]/5 that gives us freedom to
strenghten any noexcept specification.

Change-Id: I17ebd9148a181eb8496ace3a9d8010008160b564
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Giuseppe D'Angelo 2021-09-06 17:22:34 +02:00
parent 8337493301
commit c44e3b119a

View File

@ -1204,6 +1204,7 @@ void qAsConst(const T &&) = delete;
// like std::exchange
template <typename T, typename U = T>
constexpr T qExchange(T &t, U &&newValue)
noexcept(std::conjunction_v<std::is_nothrow_move_constructible<T>, std::is_nothrow_assignable<T &, U>>)
{
T old = std::move(t);
t = std::forward<U>(newValue);