From a59453d4b73376693cdaf8e5d0f081bc216de1c0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 22 Apr 2020 11:52:26 +0200 Subject: [PATCH] AK: Tweak exchange() implementation Make it constexpr and do perfect forwarding. --- AK/StdLibExtras.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 5a714fee2f..0d95585aa0 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -81,14 +81,6 @@ inline T&& move(T& arg) # pragma clang diagnostic pop #endif -template -inline T exchange(T& a, U&& b) -{ - T tmp = move(a); - a = move(b); - return tmp; -} - template inline void swap(T& a, U& b) { @@ -370,6 +362,14 @@ struct MakeUnsigned { typedef unsigned long long type; }; +template +inline constexpr T exchange(T& slot, U&& value) +{ + T old_value = move(slot); + slot = forward(value); + return old_value; +} + } using AK::ceil_div;