From patchwork Tue Oct 4 16:46:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1693 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp215728wrs; Tue, 4 Oct 2022 09:47:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4jhC65RPQozEtWr2R/xj066QakDaA04025FFQf2hM3ZagBxGezXAPWg5s7mlqHFhizXma+ X-Received: by 2002:a05:6402:2201:b0:44f:443e:2a78 with SMTP id cq1-20020a056402220100b0044f443e2a78mr23880962edb.76.1664902074689; Tue, 04 Oct 2022 09:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664902074; cv=none; d=google.com; s=arc-20160816; b=p8QtVHsncYvBorkZWLAWBTrmdDiock+0oUmVqdVSQB3fVVqa3OD4FDsmvNFbpUHItz Cqyb4gzyhdTd+SBRVRTNmVWOY5HZgosisbelBiPv8Xyhslmn9wEwcNTPv9HjdirtUB9P NXVN3VtPUgq260gARNQ5/ddWCKEhOi0rIQG5a2jSsDma+QiXECcXJMAh+Zn786oaH0+M 3NekUomiIh5/4IFtAPNqi8XYTp/C9SfFfU+LLJi0sx77PUx9vjEvJzdc0bgkuNP4HlRs IXMkA8Pa8ue/5veeqBH9Rigc5wFGXh/v0JwLfiZmcTjC1ZT6pH3arwamnFUzF+mEeYsg LLPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=VJ0AR0BCdv0WgeKaQSB/uBwG373uDhX+5nFq3LkCFlY=; b=jk+4t/aeCIOluj5eKwYNbTwoaIC3MHV6LUSURfQdUM2TvtavKPA22sCaON1G7w+5fl gYlz1m28odi8K6npHXFwO+6qWi5dAnYx5DvAEWJD1n48VF7yTB/RZyH+L8wSfHm+gadc ElmW3aFxMj3dSRRXGwaCnhzuXjl9XPzckP4kBbXsOcwvnc3mm9iJMEmH2Ng5Fftw2CjD 4fqUy7u3H5imGflietjF2wnVx/ph8FZboD6WUTM5ue/qU4RjSM5NClc/yIWd2rug4gZo b66mi2pDk2FIT9wNVbJ/DZaq/mt7QnmpWdkeW2O9FF4IR5Ox1c2xIsyxhJ9o85wesdze WwBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SdsdUSwa; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hb37-20020a170907162500b0078afea2b705si8151547ejc.320.2022.10.04.09.47.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 09:47:54 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SdsdUSwa; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0265A3857C44 for ; Tue, 4 Oct 2022 16:47:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0265A3857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664902037; bh=VJ0AR0BCdv0WgeKaQSB/uBwG373uDhX+5nFq3LkCFlY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=SdsdUSwaesZOhnvkTbfY+alG9A+F+WSdzSS87lH36KFZEhCIFPhE6nTI2r6krDxpf lSEGtEjHGSG7DTDnS8bmRekc5lSs6IcVB/bCbDYtZnDqm4MN+PBuogruEBp25n9nPU 0y2oThlOjxQRi6g5mH8m66odRl/J47z3xspf1OLI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 53A3A3858D3C for ; Tue, 4 Oct 2022 16:46:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 53A3A3858D3C Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-177-9VD6HvNSPLagep6TWMBcTQ-1; Tue, 04 Oct 2022 12:46:30 -0400 X-MC-Unique: 9VD6HvNSPLagep6TWMBcTQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1BC41C1437B; Tue, 4 Oct 2022 16:46:25 +0000 (UTC) Received: from localhost (unknown [10.33.36.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADB0DC15BA5; Tue, 4 Oct 2022 16:46:25 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Refactor seed sequence constraints in Date: Tue, 4 Oct 2022 17:46:24 +0100 Message-Id: <20221004164624.558722-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 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_LOW, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745776357813331112?= X-GMAIL-MSGID: =?utf-8?q?1745776357813331112?= Tested powerpc64le-linux. Pushed to trunk. -- >8 -- Every use of _If_seed_seq in and uses it with enable_if. We can just move the enable_if into the helper alias instead of repeating it everywhere. libstdc++-v3/ChangeLog: * include/bits/random.h (__is_seed_seq): Replace with ... (_If_seed_seq_for): ... this. * include/ext/random: Adjust to use _If_seed_seq_for. --- libstdc++-v3/include/bits/random.h | 39 ++++++++++++++++++------------ libstdc++-v3/include/ext/random | 6 ++--- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index 3e6eb9de7d9..28b37a9e5a5 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -198,16 +198,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Engine& _M_g; }; + // Detect whether a template argument _Sseq is a valid seed sequence for + // a random number engine _Engine with result type _Res. + // Used to constrain _Engine::_Engine(_Sseq&) and _Engine::seed(_Sseq&) + // as required by [rand.eng.general]. + template using __seed_seq_generate_t = decltype( std::declval<_Sseq&>().generate(std::declval(), std::declval())); - // Detect whether _Sseq is a valid seed sequence for - // a random number engine _Engine with result type _Res. template> - using __is_seed_seq = __and_< + using _If_seed_seq_for = _Require< __not_, _Engine>>, is_unsigned, __not_> @@ -263,8 +266,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "template argument substituting __m out of bounds"); template - using _If_seed_seq = typename enable_if<__detail::__is_seed_seq< - _Sseq, linear_congruential_engine, _UIntType>::value>::type; + using _If_seed_seq + = __detail::_If_seed_seq_for<_Sseq, linear_congruential_engine, + _UIntType>; public: /** The type of the generated random value. */ @@ -502,8 +506,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "template argument substituting __f out of bound"); template - using _If_seed_seq = typename enable_if<__detail::__is_seed_seq< - _Sseq, mersenne_twister_engine, _UIntType>::value>::type; + using _If_seed_seq + = __detail::_If_seed_seq_for<_Sseq, mersenne_twister_engine, + _UIntType>; public: /** The type of the generated random value. */ @@ -702,8 +707,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "template argument substituting __w out of bounds"); template - using _If_seed_seq = typename enable_if<__detail::__is_seed_seq< - _Sseq, subtract_with_carry_engine, _UIntType>::value>::type; + using _If_seed_seq + = __detail::_If_seed_seq_for<_Sseq, subtract_with_carry_engine, + _UIntType>; public: /** The type of the generated random value. */ @@ -894,8 +900,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename _RandomNumberEngine::result_type result_type; template - using _If_seed_seq = typename enable_if<__detail::__is_seed_seq< - _Sseq, discard_block_engine, result_type>::value>::type; + using _If_seed_seq + = __detail::_If_seed_seq_for<_Sseq, discard_block_engine, + result_type>; // parameter values static constexpr size_t block_size = __p; @@ -1113,8 +1120,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "template argument substituting __w out of bounds"); template - using _If_seed_seq = typename enable_if<__detail::__is_seed_seq< - _Sseq, independent_bits_engine, _UIntType>::value>::type; + using _If_seed_seq + = __detail::_If_seed_seq_for<_Sseq, independent_bits_engine, + _UIntType>; public: /** The type of the generated random value. */ @@ -1336,8 +1344,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename _RandomNumberEngine::result_type result_type; template - using _If_seed_seq = typename enable_if<__detail::__is_seed_seq< - _Sseq, shuffle_order_engine, result_type>::value>::type; + using _If_seed_seq + = __detail::_If_seed_seq_for<_Sseq, shuffle_order_engine, + result_type>; static constexpr size_t table_size = __k; diff --git a/libstdc++-v3/include/ext/random b/libstdc++-v3/include/ext/random index 4cc0e25e025..406b12b5d23 100644 --- a/libstdc++-v3/include/ext/random +++ b/libstdc++-v3/include/ext/random @@ -89,9 +89,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using _If_seed_seq - = typename std::enable_if::value - >::type; + = std::__detail::_If_seed_seq_for<_Sseq, + simd_fast_mersenne_twister_engine, + result_type>; public: static constexpr size_t state_size = _M_nstate * (16