fix(containers): fix assertion when TBitset cannot be represented by uint64

This commit is contained in:
_Redstone_c_ 2023-03-17 19:26:57 +08:00
parent 5b7a90cd0b
commit 3d951a80db
2 changed files with 24 additions and 2 deletions

View File

@ -588,7 +588,18 @@ public:
/** Converts the contents of the bitset to an uint64 integer. */
NODISCARD uint64 ToIntegral()
{
checkf(Num() <= 64, TEXT("The bitset can not be represented in uint64. Please check Num()."));
if (Num() > 64)
{
for (size_t Index = 64 / BlockWidth; Index < NumBlocks() - 1; ++Index)
{
checkf(Impl.Pointer[Index] != 0, TEXT("The bitset can not be represented in uint64. Please check Num()."));
}
const BlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
const BlockType LastBlock = Impl.Pointer[NumBlocks() - 1] & LastBlockBitmask;
checkf(LastBlock != 0, TEXT("The bitset can not be represented in uint64. Please check Num()."));
}
uint64 Result = 0;

View File

@ -383,7 +383,18 @@ public:
/** Converts the contents of the bitset to an uint64 integer. */
NODISCARD constexpr uint64 ToIntegral()
{
checkf(Num() <= 64, TEXT("The bitset can not be represented in uint64. Please check Num()."));
if constexpr (N > 64)
{
for (size_t Index = 64 / BlockWidth; Index < NumBlocks() - 1; ++Index)
{
checkf(Impl.Pointer[Index] != 0, TEXT("The bitset can not be represented in uint64. Please check Num()."));
}
const BlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
const BlockType LastBlock = Impl.Pointer[NumBlocks() - 1] & LastBlockBitmask;
checkf(LastBlock != 0, TEXT("The bitset can not be represented in uint64. Please check Num()."));
}
uint64 Result = 0;