56e97255ed4dee2f31b7100264a4113ea3218463
David Blume Add two implementations of...

David Blume authored 5 years ago

1) #pragma once
2) 
3) #define USE_TEMPLATE
4) #ifdef USE_TEMPLATE
5) 
6) #include <cstddef>
7) #include <type_traits>
8) #include <climits>
9) 
10) template <typename T>
11) T round_up_to_next_power_of_two(T x)
12) {
13)     // https://stackoverflow.com/questions/466204/rounding-up-to-next-power-of-2
dblume Add .clang-format

dblume authored 1 year ago

14)     static_assert(std::is_unsigned<T>::value, "x must be an unsigned type");
David Blume Add two implementations of...

David Blume authored 5 years ago

15)     --x;
dblume Add .clang-format

dblume authored 1 year ago

16)     for (size_t i = 1; i < sizeof(x) * CHAR_BIT; i *= 2)