File indexing completed on 2026-05-03 08:13:13
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___BIT_BIT_CEIL_H
0010 #define _LIBCPP___BIT_BIT_CEIL_H
0011
0012 #include <__assert>
0013 #include <__bit/countl.h>
0014 #include <__concepts/arithmetic.h>
0015 #include <__config>
0016 #include <limits>
0017
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 # pragma GCC system_header
0020 #endif
0021
0022 _LIBCPP_BEGIN_NAMESPACE_STD
0023
0024 #if _LIBCPP_STD_VER >= 17
0025
0026 template <class _Tp>
0027 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_ceil(_Tp __t) noexcept {
0028 if (__t < 2)
0029 return 1;
0030 const unsigned __n = numeric_limits<_Tp>::digits - std::__countl_zero((_Tp)(__t - 1u));
0031 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");
0032
0033 if constexpr (sizeof(_Tp) >= sizeof(unsigned))
0034 return _Tp{1} << __n;
0035 else {
0036 const unsigned __extra = numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits;
0037 const unsigned __ret_val = 1u << (__n + __extra);
0038 return (_Tp)(__ret_val >> __extra);
0039 }
0040 }
0041
0042 # if _LIBCPP_STD_VER >= 20
0043
0044 template <__libcpp_unsigned_integer _Tp>
0045 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept {
0046 return std::__bit_ceil(__t);
0047 }
0048
0049 # endif
0050 #endif
0051
0052 _LIBCPP_END_NAMESPACE_STD
0053
0054 #endif