feat(templates): overloads the GetTypeHash algorithm for array
This commit is contained in:
parent
1deb09480f
commit
66baa51e30
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Templates/TypeHash.h"
|
||||
#include "TypeTraits/Swappable.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
@ -71,6 +72,20 @@ FORCEINLINE constexpr void Swap(T(&A)[N], T(&B)[N])
|
||||
}
|
||||
}
|
||||
|
||||
/** Overloads the GetTypeHash algorithm for arrays. */
|
||||
template <typename T, size_t N> requires (CHashable<TRemoveAllExtents<T>>)
|
||||
FORCEINLINE constexpr size_t GetTypeHash(T(&A)[N])
|
||||
{
|
||||
size_t Result = 3516520171;
|
||||
|
||||
for (size_t Index = 0; Index < N; ++Index)
|
||||
{
|
||||
Result = HashCombine(Result, GetTypeHash(A[Index]));
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
||||
|
@ -74,7 +74,7 @@ FORCEINLINE constexpr size_t GetTypeHash(T A)
|
||||
if constexpr (sizeof(T) == 2) return GetTypeHash(*reinterpret_cast<uint16*>(&A));
|
||||
if constexpr (sizeof(T) == 4) return GetTypeHash(*reinterpret_cast<uint32*>(&A));
|
||||
if constexpr (sizeof(T) == 8) return GetTypeHash(*reinterpret_cast<uint64*>(&A));
|
||||
if constexpr (sizeof(T) == 16) return GetTypeHash(*reinterpret_cast<uint64*>(&A) + *(reinterpret_cast<uint64*>(&A) + 1));
|
||||
if constexpr (sizeof(T) == 16) return GetTypeHash(*reinterpret_cast<uint64*>(&A) ^ *(reinterpret_cast<uint64*>(&A) + 1));
|
||||
else check_no_entry();
|
||||
|
||||
return INDEX_NONE;
|
||||
|
Loading…
Reference in New Issue
Block a user