feat(templates): overloads the Swap algorithm for array

This commit is contained in:
_Redstone_c_ 2022-12-30 19:19:18 +08:00
parent e4d59b9832
commit 5338cd286a

View File

@ -73,6 +73,18 @@ FORCEINLINE constexpr void Swap(T& A, T& B)
B = MoveTemp(Temp);
}
/** Overloads the Swap algorithm for array. */
template <typename T, size_t N> requires (CMoveConstructible<T> && CMoveAssignable<T>)
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 <typename T, typename U = T> requires (CMoveConstructible<T> && CAssignableFrom<T&, U>)
FORCEINLINE constexpr T Exchange(T& A, U&& B)