mirror of
https://github.com/boostorg/core.git
synced 2025-05-10 07:13:54 +00:00
Change bit_width to return int
, LWG3656 has been applied as a DR to C++20
This commit is contained in:
parent
013c7856ce
commit
b407b5d87d
@ -45,7 +45,7 @@ template<class T>
|
|||||||
constexpr T bit_floor(T x) noexcept;
|
constexpr T bit_floor(T x) noexcept;
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
constexpr T bit_width(T x) noexcept;
|
constexpr int bit_width(T x) noexcept;
|
||||||
|
|
||||||
// Rotating
|
// Rotating
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ constant expression context.
|
|||||||
* *Requires:* `T` must be an unsigned integer type.
|
* *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`.
|
* *Returns:* If `x == 0`, 0; otherwise the maximal value `y` such that `has_single_bit(y)` is `true` and `y <= x`.
|
||||||
|
|
||||||
`template<class T> constexpr T bit_width(T x) noexcept;`
|
`template<class T> constexpr int bit_width(T x) noexcept;`
|
||||||
|
|
||||||
* *Requires:* `T` must be an unsigned integer type.
|
* *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.
|
* *Returns:* If `x == 0`, 0; otherwise one plus the base-2 logarithm of `x`, with any fractional part discarded.
|
||||||
|
@ -468,15 +468,15 @@ 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
|
// bit_width returns `int` now, https://cplusplus.github.io/LWG/issue3656
|
||||||
|
// has been applied to C++20 as a DR
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
BOOST_CONSTEXPR T bit_width( T x ) BOOST_NOEXCEPT
|
BOOST_CONSTEXPR int bit_width( T x ) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed );
|
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed );
|
||||||
|
|
||||||
return static_cast<T>(
|
return std::numeric_limits<T>::digits - boost::core::countl_zero( x );
|
||||||
std::numeric_limits<T>::digits - boost::core::countl_zero( x ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user