Avoid conversion warning in bit_width

This commit is contained in:
Peter Dimov
2022-01-19 17:20:39 +02:00
parent ea7b623b7d
commit bae7c049b0

View File

@ -446,10 +446,13 @@ BOOST_CONSTEXPR bool has_single_bit( T x ) BOOST_NOEXCEPT
return x != 0 && ( x & ( x - 1 ) ) == 0; return x != 0 && ( x & ( x - 1 ) ) == 0;
} }
// bit_width should return int, https://cplusplus.github.io/LWG/issue3656
template<class T> template<class T>
BOOST_CONSTEXPR T bit_width( T x ) BOOST_NOEXCEPT BOOST_CONSTEXPR T bit_width( T x ) BOOST_NOEXCEPT
{ {
return std::numeric_limits<T>::digits - boost::core::countl_zero( x ); return static_cast<T>(
std::numeric_limits<T>::digits - boost::core::countl_zero( x ) );
} }
template<class T> template<class T>