From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8E9233858412 for ; Thu, 14 Sep 2023 14:12:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E9233858412 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694700761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Pb0dPRnyebfZgiPyBSgZ25U7vqXLXqHjiIiWIjQMhHE=; b=UkArJzHlZ210/qddsTDgvMzZQXN+Ll2XY6dZACUjPXh/u40IHCZM3wRnpO3nogGL49RhpX wBRriio2pGzghFrxZoB7m/OdtRKmUNViLlQEIaA26aiIF14iMAfMxGSPEtP3++et2/skF3 2wUXorNz1v+ZJPwkGxGJLWKIXdHd41Y= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-46-sDu91h0MMJOR3SLem7fALw-1; Thu, 14 Sep 2023 10:12:39 -0400 X-MC-Unique: sDu91h0MMJOR3SLem7fALw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4131d4bc82dso10965141cf.3 for ; Thu, 14 Sep 2023 07:12:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694700759; x=1695305559; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Pb0dPRnyebfZgiPyBSgZ25U7vqXLXqHjiIiWIjQMhHE=; b=YDsHRi+yVehy0BEIR3Oqe7BWq8vneKbWErzCX/Srg5b6bmWvcKrxcDfRQkFuhwVBmv n5PfzmJfNHM71sS9bzo2uiNUbnVV/jEzDFKWZ/bMcQvwoCYbuvM9zIKKbOAiyS1aA0Rq JZ2XpQH+xdyXzI73jCDiM7kgkAmRoSzOTExKU57cXwVXJCOJGtQpuT/memAX2AzNeAx+ l4GPcZkwcNhMmAPoqZogZtaFGpEy9myREMAkxvCinfdG+q7J+vAMGYCTN6hPW7YwvwNa tp5GWO14gy7taSc29OLnrqQFJZaghBX4CPdc8ZHSBMx/vp7Vg26KhRd9D++5KIxRjmoi aL+A== X-Gm-Message-State: AOJu0YxWJG6dlEZtYwP/O+gLapMd1ZGHu1sRX95hRa85mCX8UXi4Br51 3pWkproSB6hWsjhj/fXMGZ5ENwkRZC653nZGcUJCSbVuoKRwpcbfrIcezRP8TFGp6EXwujj7DC5 vsjSk8SqvwPjwMUU= X-Received: by 2002:a05:622a:1308:b0:412:2ed3:38ec with SMTP id v8-20020a05622a130800b004122ed338ecmr5871958qtk.18.1694700758922; Thu, 14 Sep 2023 07:12:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGstZwfd1y5tDn3/T3KEcFcC81N+eKAjalqWtFSnGBhZ/M6VCzRBU2cM10YSvwsN/9wJ5mFA== X-Received: by 2002:a05:622a:1308:b0:412:2ed3:38ec with SMTP id v8-20020a05622a130800b004122ed338ecmr5871932qtk.18.1694700758570; Thu, 14 Sep 2023 07:12:38 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id u31-20020a05622a199f00b0040ff234b9c4sm476867qtc.25.2023.09.14.07.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 07:12:38 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Use C++20 constraints in Date: Thu, 14 Sep 2023 10:12:35 -0400 Message-ID: <20230914141235.35160-1-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.158.g94e83dcf5b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- By now it's probably safe to assume supported compilers have full concepts support in C++20 mode. And using a requires-clase instead enable_if_t inside the return type greatly reduces the sizes of the corresponding symbol names. libstdc++-v3/ChangeLog: * include/std/bit: Include . (byteswap): Use a requires-clause instead of enable_if_t inside the return type. (_If_is_unsigned_integer): Replace with ... (__unsigned_integer): ... this. (rotl): Use a requires-clause 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. --- 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) -- 2.42.0.158.g94e83dcf5b