#ifndef SPROUT_BIT_POPCOUNT_HPP #define SPROUT_BIT_POPCOUNT_HPP #include #include #include namespace sprout { namespace detail { # if SPROUT_USE_BUILTIN_BIT_OPERATION inline SPROUT_CONSTEXPR int popcount(unsigned n) { return __builtin_popcount(n); } inline SPROUT_CONSTEXPR int popcount(unsigned long n) { return __builtin_popcountl(n); } inline SPROUT_CONSTEXPR int popcount(unsigned long long n) { return __builtin_popcountll(n); } # endif template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR int popcount(T n) { return n == 0 ? 0 : 1 + sprout::detail::popcount(static_cast(n & (n - 1))) ; } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR int popcount(T n) { return sprout::detail::popcount(static_cast::type>(n)); } } // namespace detail // // popcount // template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR int popcount(T n) { return sprout::detail::popcount(n); } } // namespace sprout #endif // #ifndef SPROUT_BIT_POPCOUNT_HPP