mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:27:35 +00:00
AK: Add is_power_of_2 helper
This commit is contained in:
parent
3b27e28e67
commit
61027e5303
1 changed files with 6 additions and 0 deletions
|
@ -16,6 +16,12 @@ constexpr auto round_up_to_power_of_two(T value, U power_of_two) requires(IsInte
|
||||||
return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
|
return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr bool is_power_of_two(T value) requires(IsIntegral<T>)
|
||||||
|
{
|
||||||
|
return value && !((value) & (value - 1));
|
||||||
|
}
|
||||||
|
|
||||||
// HACK: clang-format does not format this correctly because of the requires clause above.
|
// HACK: clang-format does not format this correctly because of the requires clause above.
|
||||||
// Disabling formatting for that doesn't help either.
|
// Disabling formatting for that doesn't help either.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue