diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-22 11:52:26 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-22 12:36:35 +0200 |
commit | a59453d4b73376693cdaf8e5d0f081bc216de1c0 (patch) | |
tree | 4b7cdf465419e20b146b533c1e7fbc006973614d /AK/StdLibExtras.h | |
parent | 1a7af4d677d1659e7fb95e7704ff92f9bdc11a7f (diff) | |
download | serenity-a59453d4b73376693cdaf8e5d0f081bc216de1c0.zip |
AK: Tweak exchange() implementation
Make it constexpr and do perfect forwarding.
Diffstat (limited to 'AK/StdLibExtras.h')
-rw-r--r-- | AK/StdLibExtras.h | 16 |
1 files 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 @@ -82,14 +82,6 @@ inline T&& move(T& arg) #endif template<typename T, typename U> -inline T exchange(T& a, U&& b) -{ - T tmp = move(a); - a = move(b); - return tmp; -} - -template<typename T, typename U> inline void swap(T& a, U& b) { U tmp = move((U&)a); @@ -370,6 +362,14 @@ struct MakeUnsigned<unsigned long long> { typedef unsigned long long type; }; +template<typename T, typename U = T> +inline constexpr T exchange(T& slot, U&& value) +{ + T old_value = move(slot); + slot = forward<U>(value); + return old_value; +} + } using AK::ceil_div; |