diff --git a/maths.cpp b/maths.cpp index 1dfc701d..ec39ea19 100644 --- a/maths.cpp +++ b/maths.cpp @@ -52,33 +52,6 @@ template uint32_t util::log2 (uint32_t); template uint64_t util::log2 (uint64_t); -/////////////////////////////////////////////////////////////////////////////// -template -std::enable_if_t< - std::is_integral::value, T -> -util::round_pow2 (T value) -{ - using return_type = std::enable_if_t::value, T>; - - --value; - - for (unsigned i = 1; i < sizeof (T) * 8; i <<= 1) { - value |= value >> i; - } - - ++value; - return (return_type)value; -} - - -//----------------------------------------------------------------------------- -template uint8_t util::round_pow2 (uint8_t); -template uint16_t util::round_pow2 (uint16_t); -template uint32_t util::round_pow2 (uint32_t); -template uint64_t util::round_pow2 (uint64_t); - - /////////////////////////////////////////////////////////////////////////////// template const float util::PI; template const double util::PI; diff --git a/maths.hpp b/maths.hpp index 3f1bb930..a0c5f028 100644 --- a/maths.hpp +++ b/maths.hpp @@ -245,10 +245,23 @@ namespace util { //----------------------------------------------------------------------------- template + constexpr std::enable_if_t< std::is_integral::value, T > - round_pow2 (T value); + round_pow2 (T value) + { + using return_type = std::enable_if_t::value, T>; + + --value; + + for (unsigned i = 1; i < sizeof (T) * 8; i <<= 1) { + value |= value >> i; + } + + ++value; + return (return_type)value; + } //-----------------------------------------------------------------------------