public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-3066] libstdc++: Refactor seed sequence constraints in <random> Date: Tue, 4 Oct 2022 16:46:03 +0000 (GMT) [thread overview] Message-ID: <20221004164603.248F13858D37@sourceware.org> (raw) https://gcc.gnu.org/g:68ed966793526db02fe96605ba9c0f8bbfd59ef0 commit r13-3066-g68ed966793526db02fe96605ba9c0f8bbfd59ef0 Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Oct 4 12:57:33 2022 +0100 libstdc++: Refactor seed sequence constraints in <random> Every use of _If_seed_seq in <random> and <ext/random> 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. Diff: --- 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<typename _Sseq> using __seed_seq_generate_t = decltype( std::declval<_Sseq&>().generate(std::declval<uint_least32_t*>(), std::declval<uint_least32_t*>())); - // Detect whether _Sseq is a valid seed sequence for - // a random number engine _Engine with result type _Res. template<typename _Sseq, typename _Engine, typename _Res, typename _GenerateCheck = __seed_seq_generate_t<_Sseq>> - using __is_seed_seq = __and_< + using _If_seed_seq_for = _Require< __not_<is_same<__remove_cvref_t<_Sseq>, _Engine>>, is_unsigned<typename _Sseq::result_type>, __not_<is_convertible<_Sseq, _Res>> @@ -263,8 +266,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "template argument substituting __m out of bounds"); template<typename _Sseq> - 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<typename _Sseq> - 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<typename _Sseq> - 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<typename _Sseq> - 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<typename _Sseq> - 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<typename _Sseq> - 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<typename _Sseq> using _If_seed_seq - = typename std::enable_if<std::__detail::__is_seed_seq< - _Sseq, simd_fast_mersenne_twister_engine, result_type>::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
reply other threads:[~2022-10-04 16:46 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221004164603.248F13858D37@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).