#ifndef SPROUT_BIT_CTZ_HPP #define SPROUT_BIT_CTZ_HPP #include #include namespace sprout { namespace detail { # if SPROUT_USE_BUILTIN_BIT_OPERATION inline SPROUT_CONSTEXPR int ctz(unsigned n) { return __builtin_ctz(n); } inline SPROUT_CONSTEXPR int ctz(unsigned long n) { return __builtin_ctzl(n); } inline SPROUT_CONSTEXPR int ctz(unsigned long long n) { return __builtin_ctzll(n); } # endif template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_unsigned::value, int >::type ctz(T n) { return n & 1 ? 0 : 1 + sprout::detail::ctz(static_cast(n >> 1)) ; } template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_signed::value, int >::type ctz(T n) { return sprout::detail::ctz(static_cast::type>(n)); } } // namespace detail // // ctz // template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_integral::value, int >::type ctz(T n) { return sprout::detail::ctz(n); } } // namespace sprout #endif // #ifndef SPROUT_BIT_CTZ_HPP