Skip to content

Commit

Permalink
AK: Add is_power_of_2 helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Panky-codes authored and IdanHo committed Jan 29, 2022
1 parent 3b27e28 commit 61027e5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions AK/StdLibExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

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.
// Disabling formatting for that doesn't help either.
//
Expand Down

0 comments on commit 61027e5

Please sign in to comment.