Skip to content

Commit 26804c0

Browse files
committed
[core] add IsPowerOfTwo() to bit utils
1 parent c6da990 commit 26804c0

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

core/foundation/inc/ROOT/BitUtils.hxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <algorithm>
1616
#include <cassert>
1717
#include <cstddef>
18+
#include <cstdint>
1819
#include <type_traits>
1920

2021
#ifdef _MSC_VER
@@ -24,12 +25,17 @@
2425
namespace ROOT {
2526
namespace Internal {
2627

28+
inline bool IsPowerOfTwo(std::uint64_t v)
29+
{
30+
return (v & (v - 1)) == 0;
31+
}
32+
2733
/// Return true if \p align is a valid C++ alignment value: strictly positive
2834
/// and a power of two. This is the set of values accepted by
2935
/// `::operator new[](n, std::align_val_t(align))`.
3036
inline constexpr bool IsValidAlignment(std::size_t align) noexcept
3137
{
32-
return align > 0 && (align & (align - 1)) == 0;
38+
return align > 0 && IsPowerOfTwo(align);
3339
}
3440

3541
/// Round \p value up to the next multiple of \p align.

0 commit comments

Comments
 (0)