From d05e10b1c0b99c9839888f0705cf87cab8f3db6e Mon Sep 17 00:00:00 2001 From: SergeyMakeev Date: Sat, 3 Feb 2024 15:45:02 -0800 Subject: [PATCH] add pow2 static assert --- ExcaliburHash/ExcaliburHash.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ExcaliburHash/ExcaliburHash.h b/ExcaliburHash/ExcaliburHash.h index 084b0db..9ae77f7 100644 --- a/ExcaliburHash/ExcaliburHash.h +++ b/ExcaliburHash/ExcaliburHash.h @@ -320,7 +320,7 @@ template ((inlineItems + i), std::move(*otherInlineItem.key())); - + // move inline storage value (if any) if (hasValidValue) { @@ -333,7 +333,7 @@ template ((inlineItems + i), std::move(*from[i].key())); @@ -1006,9 +1006,16 @@ template inline static constexpr bool isPow2(INTEGRAL_TYPE x) noexcept + { + static_assert(std::is_integral::value, "isPow2 must be called on an integer type."); + return (x & (x - 1)) == 0 && (x != 0); + } + // We need this inline storage to keep `m_storage` not null all the time. // This will save us from `empty()` check inside `find()` function implementation static_assert(kNumInlineItems != 0, "Num inline items can't be zero!"); + static_assert(isPow2(kNumInlineItems), "Num inline items should be power of two"); typename std::aligned_storage::type m_inlineStorage; static_assert(sizeof(m_inlineStorage) == (sizeof(TItem) * kNumInlineItems), "Incorrect sizeof"); };