From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id DFF883858D35; Fri, 15 Sep 2023 19:26:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFF883858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694805997; bh=aFlzu7a67RJRhVXyrCf6+IussmDyZf1xahb/WEB8Zeo=; h=From:To:Subject:Date:From; b=qR9suQJpRNMRPreEXxtsXecTT3V4CvtzTQtknaf8wGJ28V2qtxv1exeQMeUHQJaWM eKbMoIcnEFwZhkvE3etD/UFT3XDYSrHcFMMt7bSdOTmf3GVk1k4R23Qp6vFxwDDC42 B1nOBNxTUEmLw3+pvYVum+156tcuI/VGvFqHTiZ8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-4043] libstdc++: Use C++20 constraints in X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: b09193fb0686b70ca26b7fa87f9d258503d63837 X-Git-Newrev: fd5a858eb5ef93c4ac7b0399b67d46805d2dabec Message-Id: <20230915192637.DFF883858D35@sourceware.org> Date: Fri, 15 Sep 2023 19:26:37 +0000 (GMT) List-Id: https://gcc.gnu.org/g:fd5a858eb5ef93c4ac7b0399b67d46805d2dabec commit r14-4043-gfd5a858eb5ef93c4ac7b0399b67d46805d2dabec Author: Patrick Palka Date: Fri Sep 15 15:26:26 2023 -0400 libstdc++: Use C++20 constraints in Using a type-constraint instead of enable_if_t in the return types of these functions greatly reduces the size of their mangled names. And by now it's probably safe to assume recent compilers have sufficient C++20 concepts support to handle such constraints. libstdc++-v3/ChangeLog: * include/std/bit: Include . (byteswap): Use a type-constraint instead of enable_if_t inside the return type, and use std::integral. (_If_is_unsigned_integer): Replace with ... (__unsigned_integer): ... this. (rotl): Use a type-constraint instead of enable_if_t inside the return type. (countl_zero): Likewise. (countl_one): Likewise. (countr_zero): Likewise. (countr_one): Likewise. (popcount): Likewise. (has_single_bit): Likewise. (bit_ceil): Likewise. (bit_floor): Likewise. (bit_width): Likewise. Diff: --- libstdc++-v3/include/std/bit | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/libstdc++-v3/include/std/bit b/libstdc++-v3/include/std/bit index 987b6cdbb35..dce61b440c5 100644 --- a/libstdc++-v3/include/std/bit +++ b/libstdc++-v3/include/std/bit @@ -33,6 +33,7 @@ #if __cplusplus >= 201402L +#include // for std::integral #include #if _GLIBCXX_HOSTED || __has_include() @@ -103,9 +104,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return An object of the same type, with the bytes reversed. * @since C++23 */ - template + template [[nodiscard]] - constexpr enable_if_t::value, _Tp> + constexpr _Tp byteswap(_Tp __value) noexcept { if constexpr (sizeof(_Tp) == 1) @@ -378,54 +379,53 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifdef __cpp_lib_bitops // C++ >= 20 /// @cond undocumented - template - using _If_is_unsigned_integer - = enable_if_t<__is_unsigned_integer<_Tp>::value, _Up>; + template + concept __unsigned_integer = __is_unsigned_integer<_Tp>::value; /// @endcond // [bit.rot], rotating /// Rotate `x` to the left by `s` bits. - template - [[nodiscard]] constexpr _If_is_unsigned_integer<_Tp> + template<__unsigned_integer _Tp> + [[nodiscard]] constexpr _Tp rotl(_Tp __x, int __s) noexcept { return std::__rotl(__x, __s); } /// Rotate `x` to the right by `s` bits. - template - [[nodiscard]] constexpr _If_is_unsigned_integer<_Tp> + template<__unsigned_integer _Tp> + [[nodiscard]] constexpr _Tp rotr(_Tp __x, int __s) noexcept { return std::__rotr(__x, __s); } // [bit.count], counting /// The number of contiguous zero bits, starting from the highest bit. - template - constexpr _If_is_unsigned_integer<_Tp, int> + template<__unsigned_integer _Tp> + constexpr int countl_zero(_Tp __x) noexcept { return std::__countl_zero(__x); } /// The number of contiguous one bits, starting from the highest bit. - template - constexpr _If_is_unsigned_integer<_Tp, int> + template<__unsigned_integer _Tp> + constexpr int countl_one(_Tp __x) noexcept { return std::__countl_one(__x); } /// The number of contiguous zero bits, starting from the lowest bit. - template - constexpr _If_is_unsigned_integer<_Tp, int> + template<__unsigned_integer _Tp> + constexpr int countr_zero(_Tp __x) noexcept { return std::__countr_zero(__x); } /// The number of contiguous one bits, starting from the lowest bit. - template - constexpr _If_is_unsigned_integer<_Tp, int> + template<__unsigned_integer _Tp> + constexpr int countr_one(_Tp __x) noexcept { return std::__countr_one(__x); } /// The number of bits set in `x`. - template - constexpr _If_is_unsigned_integer<_Tp, int> + template<__unsigned_integer _Tp> + constexpr int popcount(_Tp __x) noexcept { return std::__popcount(__x); } #endif // __cpp_lib_bitops @@ -434,28 +434,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // [bit.pow.two], integral powers of 2 /// True if `x` is a power of two, false otherwise. - template - constexpr _If_is_unsigned_integer<_Tp, bool> + template<__unsigned_integer _Tp> + constexpr bool has_single_bit(_Tp __x) noexcept { return std::__has_single_bit(__x); } /// The smallest power-of-two not less than `x`. - template - constexpr _If_is_unsigned_integer<_Tp> + template<__unsigned_integer _Tp> + constexpr _Tp bit_ceil(_Tp __x) noexcept { return std::__bit_ceil(__x); } /// The largest power-of-two not greater than `x`. - template - constexpr _If_is_unsigned_integer<_Tp> + template<__unsigned_integer _Tp> + constexpr _Tp bit_floor(_Tp __x) noexcept { return std::__bit_floor(__x); } // _GLIBCXX_RESOLVE_LIB_DEFECTS // 3656. Inconsistent bit operations returning a count /// The smallest integer greater than the base-2 logarithm of `x`. - template - constexpr _If_is_unsigned_integer<_Tp, int> + template<__unsigned_integer _Tp> + constexpr int bit_width(_Tp __x) noexcept { return std::__bit_width(__x); } #endif // defined (__cpp_lib_int_pow2)