#pragma once #define USE_TEMPLATE #ifdef USE_TEMPLATE #include #include #include template T round_up_to_next_power_of_two(T x) { // https://stackoverflow.com/questions/466204/rounding-up-to-next-power-of-2 static_assert(std::is_unsigned::value, "x must be an unsigned type"); --x; for(size_t i = 1; i < sizeof(x) * CHAR_BIT; i *= 2) x |= x >> i; return ++x; } #else unsigned round_up_to_next_power_of_two(unsigned x); #endif unsigned another_round_up_to_next_power_of_two(unsigned x);