[committed] libstdc++: Refactor seed sequence constraints in <random>

Message ID 20221004164624.558722-1-jwakely@redhat.com
State New, archived
Headers
Series [committed] libstdc++: Refactor seed sequence constraints in <random> |

Commit Message

Jonathan Wakely Oct. 4, 2022, 4:46 p.m. UTC
  Tested powerpc64le-linux. Pushed to trunk.

-- >8 --

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.
---
 libstdc++-v3/include/bits/random.h | 39 ++++++++++++++++++------------
 libstdc++-v3/include/ext/random    |  6 ++---
 2 files changed, 27 insertions(+), 18 deletions(-)
  

Patch

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