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.129.124]) by sourceware.org (Postfix) with ESMTPS id C068C3858412 for ; Thu, 14 Sep 2023 17:55:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C068C3858412 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=1694714105; 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: in-reply-to:in-reply-to:references:references; bh=pbBL8jD+MnaZiU1NcNeQKq8zMHOXUj5FL5jyDlyViFg=; b=FY8yDZ2S7zKOpx9zrOdtBHJ6pTbtsZVF2OU42433Z2tDYrB05VGarIXWP6h4dYZQP2kSpn xa2oQuBuiMwcYKOB99F75tLiErCE/8Nm7Oc3qbe8jCyw1OMJUftaPg25OmZFxPBY404AB7 XTpLLHBJ+adHSXIQG6uhqUQjP2Qg1Lw= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-387-f_6EKNuiNXSww7wl_5DCOw-1; Thu, 14 Sep 2023 13:55:04 -0400 X-MC-Unique: f_6EKNuiNXSww7wl_5DCOw-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2bfaad83575so14967641fa.2 for ; Thu, 14 Sep 2023 10:55:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694714102; x=1695318902; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pbBL8jD+MnaZiU1NcNeQKq8zMHOXUj5FL5jyDlyViFg=; b=BqwR/bOHi/9IbnykwgKMVGhk9iJvDKewS6jWYIHKIqNm31YvF4MOx35Hrtg2TWgYtE kD2LHTXJHeEUs4R9FuH7ZaRmFJD6cv+4t3LfXK8ddgo+Wrxfl2cvxK8K0nA/fflu8uBB r+kVUTDLV4etDdC09aitbQkf7cAMDYkXlYvucmO6xaaXxPzz15iqvUlTt6i8On5PfWiL /O2uvJmDzCP3G5A0iGLapLUki4nOP4t5emnCnby65CQq+eq4uR/B/x4vJFEC9f9K/Qsq U3TXM8p1jl+3QujCqh2nso9RBTreSxw4VxigEwQqfZ/5NRbXrmUZAq1bVDoZrY7MELlS F3mQ== X-Gm-Message-State: AOJu0YwRsmBnzV+W2NOXehOF/izW0kuO+DTug+WedQpH7nyjGGJxTvjV f5QZFRkpjH2UgNVd+bSa7x+OW8fBfqAaBqZURAcjYG8nynxXKrnsGTsN0OxL9Yhi6Z5yMRHQksr b20jnVGxwRaV3OVgOj6JCaTzM1tErf8395df10Hs= X-Received: by 2002:a2e:8ed3:0:b0:2b9:53bd:47a7 with SMTP id e19-20020a2e8ed3000000b002b953bd47a7mr5500813ljl.30.1694714102659; Thu, 14 Sep 2023 10:55:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHv770AxHcJ1zoKLAJFcNGNm0MYo/b/rhz0fKUEJHKmkMW2rBu1IQ7C+p8amGREYelVOw8JDNfPpgtQTUDDh9U= X-Received: by 2002:a2e:8ed3:0:b0:2b9:53bd:47a7 with SMTP id e19-20020a2e8ed3000000b002b953bd47a7mr5500798ljl.30.1694714102255; Thu, 14 Sep 2023 10:55:02 -0700 (PDT) MIME-Version: 1.0 References: <20230914141235.35160-1-ppalka@redhat.com> In-Reply-To: <20230914141235.35160-1-ppalka@redhat.com> From: Jonathan Wakely Date: Thu, 14 Sep 2023 18:54:50 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Use C++20 constraints in To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-12.1 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_H4,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: On Thu, 14 Sept 2023 at 15:13, Patrick Palka via Libstdc++ wrote: > > 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. Clang 14.0.0 is good enough for these uses. It doesn't handle our properly, or conditionally trivial special member functions, but that's not a problem here. > And using a requires-clase instead > enable_if_t inside the return type greatly reduces the sizes of the > corresponding symbol names. Will that change when we start to mangle constraints? :-) OK for trunk. > > 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 >