From c04c56ed325a55a156c94cbcbb009286dcc02700 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 2 Feb 2016 11:32:29 +1100 Subject: [PATCH] maths: make is_pow2 constexpr --- maths.cpp | 16 ---------------- maths.hpp | 8 ++++++-- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/maths.cpp b/maths.cpp index 8891d707..59fd2144 100644 --- a/maths.cpp +++ b/maths.cpp @@ -24,22 +24,6 @@ #include -/////////////////////////////////////////////////////////////////////////////// -template -bool -util::is_pow2 (T value) -{ - typedef typename std::enable_if::value, bool>::type return_type; - return (return_type)(value && !(value & (value - 1))); -} - - -template bool util::is_pow2 (uint8_t); -template bool util::is_pow2 (uint16_t); -template bool util::is_pow2 (uint32_t); -template bool util::is_pow2 (uint64_t); - - /////////////////////////////////////////////////////////////////////////////// template T diff --git a/maths.hpp b/maths.hpp index 1a4c5214..38205e33 100644 --- a/maths.hpp +++ b/maths.hpp @@ -67,8 +67,12 @@ namespace util { //------------------------------------------------------------------------- template - bool - is_pow2 (T value); + constexpr + std::enable_if_t::value, bool> + is_pow2 [[gnu::const]] (T value) + { + return value && !(value & (value - 1)); + } //-----------------------------------------------------------------------------