From b0e7c01f13911a24fe8482650470532eabcf9664 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Fri, 30 Dec 2022 19:19:18 +0800 Subject: [PATCH] feat(templates): overloads the Swap algorithm for array. --- Redcraft.Utility/Source/Public/Templates/Utility.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Redcraft.Utility/Source/Public/Templates/Utility.h b/Redcraft.Utility/Source/Public/Templates/Utility.h index 793bab5..b66dbc5 100644 --- a/Redcraft.Utility/Source/Public/Templates/Utility.h +++ b/Redcraft.Utility/Source/Public/Templates/Utility.h @@ -73,6 +73,18 @@ FORCEINLINE constexpr void Swap(T& A, T& B) B = MoveTemp(Temp); } +/** Overloads the Swap algorithm for array. */ +template requires (CMoveConstructible && CMoveAssignable) +FORCEINLINE constexpr void Swap(T(&A)[N], T(&B)[N]) +{ + for (size_t Index = 0; Index < N; ++Index) + { + T Temp = MoveTemp(A[Index]); + A[Index] = MoveTemp(B[Index]); + B[Index] = MoveTemp(Temp); + } +} + /** Replaces the value of 'A' with 'B' and returns the old value of 'A'. */ template requires (CMoveConstructible && CAssignableFrom) FORCEINLINE constexpr T Exchange(T& A, U&& B)