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.
This commit is contained in:
Danny Robson 2018-12-06 15:56:37 +11:00
parent 5627f0f280
commit 9eb2784d84

View File

@ -67,19 +67,29 @@ namespace cruft {
///////////////////////////////////////////////////////////////////////////
template <
typename T,
typename = std::enable_if_t<
std::is_integral_v<T>
>
>
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].