Explorar o código

AK: Extend round_to_power_of_two to types other than `unsigned`

The previous implementation hardcoded unsigned, when the same logic
easily extends to unsigned long, signed types, and other Integral types.
Andrew Kaster %!s(int64=4) %!d(string=hai) anos
pai
achega
eae14f4ba6
Modificáronse 1 ficheiros con 2 adicións e 1 borrados
  1. 2 1
      AK/StdLibExtras.h

+ 2 - 1
AK/StdLibExtras.h

@@ -10,7 +10,8 @@
 
 
 #include <AK/Assertions.h>
 #include <AK/Assertions.h>
 
 
-constexpr unsigned round_up_to_power_of_two(unsigned value, unsigned power_of_two)
+template<typename T, typename U>
+constexpr auto round_up_to_power_of_two(T value, U power_of_two) requires(IsIntegral<T>&& IsIntegral<U>)
 {
 {
     return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
     return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
 }
 }