From 9eb2784d84a986e0402c59ee00807fe6286fc3bb Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 6 Dec 2018 15:56:37 +1100 Subject: [PATCH] bitwise: convert popcount template into explicit overloads popcount, popcountl, and popcountll need to be used for each appropriate fundamental type. It's easiest to just provide overloads for popcount for the few cases we have available than to deal with templates. --- bitwise.hpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/bitwise.hpp b/bitwise.hpp index d3b5f016..ec31a78e 100644 --- a/bitwise.hpp +++ b/bitwise.hpp @@ -67,19 +67,29 @@ namespace cruft { /////////////////////////////////////////////////////////////////////////// - template < - typename T, - typename = std::enable_if_t< - std::is_integral_v - > - > - constexpr T - popcount (T t) + constexpr unsigned + popcount (unsigned t) { return __builtin_popcount (t); } + //------------------------------------------------------------------------- + constexpr unsigned long + popcount (unsigned long t) + { + return __builtin_popcountl (t); + } + + + //------------------------------------------------------------------------- + constexpr unsigned long long + popcount (unsigned long long t) + { + return __builtin_popcountll (t); + } + + /////////////////////////////////////////////////////////////////////////// /// returns the integral value composed of the bits from `val' in the /// inclusive range [lo, hi].