diff --git a/doc/bit.qbk b/doc/bit.qbk index e8d5fce..81b9536 100644 --- a/doc/bit.qbk +++ b/doc/bit.qbk @@ -45,7 +45,7 @@ template constexpr T bit_floor(T x) noexcept; template -constexpr T bit_width(T x) noexcept; +constexpr int bit_width(T x) noexcept; // Rotating @@ -119,7 +119,7 @@ constant expression context. * *Requires:* `T` must be an unsigned integer type. * *Returns:* If `x == 0`, 0; otherwise the maximal value `y` such that `has_single_bit(y)` is `true` and `y <= x`. -`template constexpr T bit_width(T x) noexcept;` +`template constexpr int bit_width(T x) noexcept;` * *Requires:* `T` must be an unsigned integer type. * *Returns:* If `x == 0`, 0; otherwise one plus the base-2 logarithm of `x`, with any fractional part discarded. diff --git a/include/boost/core/bit.hpp b/include/boost/core/bit.hpp index 69e1763..5d14685 100644 --- a/include/boost/core/bit.hpp +++ b/include/boost/core/bit.hpp @@ -468,15 +468,15 @@ BOOST_CONSTEXPR bool has_single_bit( T x ) BOOST_NOEXCEPT return x != 0 && ( x & ( x - 1 ) ) == 0; } -// bit_width should return int, https://cplusplus.github.io/LWG/issue3656 +// bit_width returns `int` now, https://cplusplus.github.io/LWG/issue3656 +// has been applied to C++20 as a DR template -BOOST_CONSTEXPR T bit_width( T x ) BOOST_NOEXCEPT +BOOST_CONSTEXPR int bit_width( T x ) BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( std::numeric_limits::is_integer && !std::numeric_limits::is_signed ); - return static_cast( - std::numeric_limits::digits - boost::core::countl_zero( x ) ); + return std::numeric_limits::digits - boost::core::countl_zero( x ); } template