From 5bcb3b4d80d9d973acafe9d5a1c12d151b4b99fa Mon Sep 17 00:00:00 2001
From: Paolo Carlini <paolo.carlini@oracle.com>
Date: Fri, 2 Nov 2012 10:45:25 +0000
Subject: [PATCH] re PR libstdc++/55169
 (std::discrete_distribution::operator(generator&) makes unnecessary copy of
 parameter vector)

2012-11-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/55169
	* include/bits/random.h: Remove all uses of param().
	(chi_squared_distribution<>::__generate_impl(_ForwardIterator,
	_ForwardIterator, _UniformRandomNumberGenerator&): Declare
	* include/bits/random.tcc: ... define.
	* include/ext/random: Remove all uses of param().

From-SVN: r193092
---
 libstdc++-v3/ChangeLog               |  13 +-
 libstdc++-v3/include/bits/random.h   | 308 +++++++++++++--------------
 libstdc++-v3/include/bits/random.tcc |  16 +-
 libstdc++-v3/include/ext/random      |  53 +++--
 4 files changed, 202 insertions(+), 188 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index e82d988bb2e6..907fa7c7fc64 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+2012-11-02  Paolo Carlini  <paolo.carlini@oracle.com>
+
+	PR libstdc++/55169
+	* include/bits/random.h: Remove all uses of param().
+	(chi_squared_distribution<>::__generate_impl(_ForwardIterator,
+	_ForwardIterator, _UniformRandomNumberGenerator&): Declare
+	* include/bits/random.tcc: ... define.
+	* include/ext/random: Remove all uses of param().
+
 2012-11-02  Gerald Pfeifer  <gerald@pfeifer.com>
 
 	* doc/xml/manual/allocator.xml: Update reference to Hoard.
@@ -27,7 +36,7 @@
 	* testsuite/23_containers/forward_list/cons/14.cc: New.
 
 2012-11-02  Gerald Pfeifer  <gerald@pfeifer.com>
-	
+
 	* doc/xml/manual/codecvt.xml: Fix reference to Austin Common
 	Standards Revision Group.
 	* doc/xml/manual/messages.xml: Ditto.
@@ -39,7 +48,7 @@
 	STL at SGI.
 	Update reference to COM at Microsoft.
 	Update reference to Worst-case efficient priority queues at ACM.
-	
+
 2012-11-01  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
 	* testsuite/18_support/initializer_list/range_access.cc: Fix copying
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index f31f5535dee3..d87a35e539d0 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -1767,7 +1767,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-        { return this->operator()(__urng, this->param()); }
+        { return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -1779,7 +1779,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -1796,6 +1796,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two uniform integer distributions have
+       *        the same parameters.
+       */
+      friend bool
+      operator==(const uniform_int_distribution& __d1,
+		 const uniform_int_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
     private:
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -1807,16 +1816,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-   * @brief Return true if two uniform integer distributions have
-   *        the same parameters.
-   */
-  template<typename _IntType>
-    inline bool
-    operator==(const std::uniform_int_distribution<_IntType>& __d1,
-	       const std::uniform_int_distribution<_IntType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
    * @brief Return true if two uniform integer distributions have
    *        different parameters.
@@ -1972,7 +1971,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-        { return this->operator()(__urng, this->param()); }
+        { return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -1989,7 +1988,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -2006,6 +2005,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two uniform real distributions have
+       *        the same parameters.
+       */
+      friend bool
+      operator==(const uniform_real_distribution& __d1,
+		 const uniform_real_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
     private:
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -2017,16 +2025,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-   * @brief Return true if two uniform real distributions have
-   *        the same parameters.
-   */
-  template<typename _IntType>
-    inline bool
-    operator==(const std::uniform_real_distribution<_IntType>& __d1,
-	       const std::uniform_real_distribution<_IntType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
    * @brief Return true if two uniform real distributions have
    *        different parameters.
@@ -2195,7 +2193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -2207,7 +2205,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -2397,7 +2395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+        { return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -2410,7 +2408,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -2435,7 +2433,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const lognormal_distribution& __d1,
 		 const lognormal_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_nd == __d2._M_nd); }
 
       /**
@@ -2619,7 +2617,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -2631,7 +2629,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -2656,7 +2654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const gamma_distribution& __d1,
 		 const gamma_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_nd == __d2._M_nd); }
 
       /**
@@ -2824,7 +2822,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate_impl(__f, __t, __urng, _M_gd.param()); }
+        { this->__generate_impl(__f, __t, __urng); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -2840,9 +2838,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(result_type* __f, result_type* __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ typename std::gamma_distribution<result_type>::param_type
-	    __p2(_M_gd.param());
-	  this->__generate_impl(__f, __t, __urng, __p2); }
+        { this->__generate_impl(__f, __t, __urng); }
 
       template<typename _UniformRandomNumberGenerator>
 	void
@@ -2861,7 +2857,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const chi_squared_distribution& __d1,
 		 const chi_squared_distribution& __d2)
-      { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
+      { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
 
       /**
        * @brief Inserts a %chi_squared_distribution random number distribution
@@ -2894,13 +2890,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   std::chi_squared_distribution<_RealType1>& __x);
 
     private:
+      template<typename _ForwardIterator,
+	       typename _UniformRandomNumberGenerator>
+	void
+	__generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+			_UniformRandomNumberGenerator& __urng);
+
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
 	void
 	__generate_impl(_ForwardIterator __f, _ForwardIterator __t,
 			_UniformRandomNumberGenerator& __urng,
-			typename std::gamma_distribution<result_type>::param_type&
-			__p);
+			const typename
+			std::gamma_distribution<result_type>::param_type& __p);
 
       param_type _M_param;
 
@@ -3024,7 +3026,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -3036,7 +3038,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -3053,6 +3055,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two Cauchy distributions have
+       *        the same parameters.
+       */
+      friend bool
+      operator==(const cauchy_distribution& __d1,
+		 const cauchy_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
     private:
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -3064,16 +3075,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-   * @brief Return true if two Cauchy distributions have
-   *        the same parameters.
-   */
-  template<typename _RealType>
-    inline bool
-    operator==(const std::cauchy_distribution<_RealType>& __d1,
-	       const std::cauchy_distribution<_RealType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
    * @brief Return true if two Cauchy distributions have
    *        different parameters.
@@ -3278,7 +3279,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const fisher_f_distribution& __d1,
 		 const fisher_f_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_gd_x == __d2._M_gd_x
 		&& __d1._M_gd_y == __d2._M_gd_y); }
 
@@ -3492,7 +3493,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const student_t_distribution& __d1,
 		 const student_t_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
 
       /**
@@ -3664,7 +3665,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     template<typename _UniformRandomNumberGenerator>
       result_type
       operator()(_UniformRandomNumberGenerator& __urng)
-      { return this->operator()(__urng, this->param()); }
+      { return this->operator()(__urng, _M_param); }
 
     template<typename _UniformRandomNumberGenerator>
       result_type
@@ -3684,7 +3685,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       __generate(_ForwardIterator __f, _ForwardIterator __t,
 		 _UniformRandomNumberGenerator& __urng)
-      { this->__generate(__f, __t, __urng, this->param()); }
+      { this->__generate(__f, __t, __urng, _M_param); }
 
     template<typename _ForwardIterator,
 	     typename _UniformRandomNumberGenerator>
@@ -3700,6 +3701,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		 const param_type& __p)
       { this->__generate_impl(__f, __t, __urng, __p); }
 
+    /**
+     * @brief Return true if two Bernoulli distributions have
+     *        the same parameters.
+     */
+    friend bool
+    operator==(const bernoulli_distribution& __d1,
+	       const bernoulli_distribution& __d2)
+    { return __d1._M_param == __d2._M_param; }
+
   private:
     template<typename _ForwardIterator,
 	     typename _UniformRandomNumberGenerator>
@@ -3711,15 +3721,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     param_type _M_param;
   };
 
-  /**
-   * @brief Return true if two Bernoulli distributions have
-   *        the same parameters.
-   */
-  inline bool
-  operator==(const std::bernoulli_distribution& __d1,
-	     const std::bernoulli_distribution& __d2)
-  { return __d1.param() == __d2.param(); }
-
   /**
    * @brief Return true if two Bernoulli distributions have
    *        different parameters.
@@ -3892,7 +3893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -3904,7 +3905,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -3930,9 +3931,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
         operator==(const binomial_distribution& __d1,
 		   const binomial_distribution& __d2)
 #ifdef _GLIBCXX_USE_C99_MATH_TR1
-	{ return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
+	{ return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
 #else
-        { return __d1.param() == __d2.param(); }
+        { return __d1._M_param == __d2._M_param; }
 #endif
 
       /**
@@ -4104,7 +4105,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -4116,7 +4117,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -4133,6 +4134,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two geometric distributions have
+       *        the same parameters.
+       */
+      friend bool
+      operator==(const geometric_distribution& __d1,
+		 const geometric_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
     private:
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -4144,16 +4154,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-   * @brief Return true if two geometric distributions have
-   *        the same parameters.
-   */
-  template<typename _IntType>
-    inline bool
-    operator==(const std::geometric_distribution<_IntType>& __d1,
-	       const std::geometric_distribution<_IntType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
    * @brief Return true if two geometric distributions have
    *        different parameters.
@@ -4349,7 +4349,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const negative_binomial_distribution& __d1,
 		 const negative_binomial_distribution& __d2)
-      { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
+      { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
 
       /**
        * @brief Inserts a %negative_binomial_distribution random
@@ -4529,7 +4529,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -4541,7 +4541,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -4567,9 +4567,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       operator==(const poisson_distribution& __d1,
 		 const poisson_distribution& __d2)
 #ifdef _GLIBCXX_USE_C99_MATH_TR1
-      { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
+      { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
 #else
-      { return __d1.param() == __d2.param(); }
+      { return __d1._M_param == __d2._M_param; }
 #endif
 
       /**
@@ -4739,7 +4739,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-        { return this->operator()(__urng, this->param()); }
+        { return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -4756,7 +4756,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -4773,6 +4773,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two exponential distributions have the same
+       *        parameters.
+       */
+      friend bool
+      operator==(const exponential_distribution& __d1,
+		 const exponential_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
     private:
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -4784,16 +4793,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-   * @brief Return true if two exponential distributions have the same
-   *        parameters.
-   */
-  template<typename _RealType>
-    inline bool
-    operator==(const std::exponential_distribution<_RealType>& __d1,
-	       const std::exponential_distribution<_RealType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
    * @brief Return true if two exponential distributions have different
    *        parameters.
@@ -4948,7 +4947,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -4960,7 +4959,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -4977,6 +4976,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two Weibull distributions have the same
+       *        parameters.
+       */
+      friend bool
+      operator==(const weibull_distribution& __d1,
+		 const weibull_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
     private:
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -4988,16 +4996,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-   /**
-    * @brief Return true if two Weibull distributions have the same
-    *        parameters.
-    */
-  template<typename _RealType>
-    inline bool
-    operator==(const std::weibull_distribution<_RealType>& __d1,
-	       const std::weibull_distribution<_RealType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
    /**
     * @brief Return true if two Weibull distributions have different
     *        parameters.
@@ -5152,7 +5150,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -5164,7 +5162,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -5181,6 +5179,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two extreme value distributions have the same
+       *        parameters.
+       */
+      friend bool
+      operator==(const extreme_value_distribution& __d1,
+		 const extreme_value_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
     private:
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -5192,16 +5199,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-    * @brief Return true if two extreme value distributions have the same
-    *        parameters.
-   */
-  template<typename _RealType>
-    inline bool
-    operator==(const std::extreme_value_distribution<_RealType>& __d1,
-	       const std::extreme_value_distribution<_RealType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
     * @brief Return true if two extreme value distributions have different
     *        parameters.
@@ -5382,7 +5379,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -5394,7 +5391,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -5411,6 +5408,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two discrete distributions have the same
+       *        parameters.
+       */
+      friend bool
+      operator==(const discrete_distribution& __d1,
+		 const discrete_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
       /**
        * @brief Inserts a %discrete_distribution random number distribution
        * @p __x into the output stream @p __os.
@@ -5453,16 +5459,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-    * @brief Return true if two discrete distributions have the same
-    *        parameters.
-    */
-  template<typename _IntType>
-    inline bool
-    operator==(const std::discrete_distribution<_IntType>& __d1,
-	       const std::discrete_distribution<_IntType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
     * @brief Return true if two discrete distributions have different
     *        parameters.
@@ -5649,7 +5645,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -5661,7 +5657,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -5678,6 +5674,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two piecewise constant distributions have the
+       *        same parameters.
+       */
+      friend bool
+      operator==(const piecewise_constant_distribution& __d1,
+		 const piecewise_constant_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
       /**
        * @brief Inserts a %piecewise_constan_distribution random
        *        number distribution @p __x into the output stream @p __os.
@@ -5721,16 +5726,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-    * @brief Return true if two piecewise constant distributions have the
-    *        same parameters.
-   */
-  template<typename _RealType>
-    inline bool
-    operator==(const std::piecewise_constant_distribution<_RealType>& __d1,
-	       const std::piecewise_constant_distribution<_RealType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
     * @brief Return true if two piecewise constant distributions have 
     *        different parameters.
@@ -5920,7 +5915,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -5932,7 +5927,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -5949,6 +5944,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two piecewise linear distributions have the
+       *        same parameters.
+       */
+      friend bool
+      operator==(const piecewise_linear_distribution& __d1,
+		 const piecewise_linear_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
       /**
        * @brief Inserts a %piecewise_linear_distribution random number
        *        distribution @p __x into the output stream @p __os.
@@ -5992,16 +5996,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-    * @brief Return true if two piecewise linear distributions have the
-    *        same parameters.
-   */
-  template<typename _RealType>
-    inline bool
-    operator==(const std::piecewise_linear_distribution<_RealType>& __d1,
-	       const std::piecewise_linear_distribution<_RealType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
     * @brief Return true if two piecewise linear distributions have
     *        different parameters.
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
index f2edc3e66eed..0f44ee852290 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -2150,6 +2150,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return __is;
     }
 
+  template<typename _RealType>
+    template<typename _ForwardIterator,
+	     typename _UniformRandomNumberGenerator>
+      void
+      std::chi_squared_distribution<_RealType>::
+      __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+		      _UniformRandomNumberGenerator& __urng)
+      {
+	__glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+	while (__f != __t)
+	  *__f++ = 2 * _M_gd(__urng);
+      }
 
   template<typename _RealType>
     template<typename _ForwardIterator,
@@ -2158,8 +2170,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       std::chi_squared_distribution<_RealType>::
       __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
 		      _UniformRandomNumberGenerator& __urng,
-		      typename std::gamma_distribution<result_type>::param_type&
-		      __p)
+		      const typename
+		      std::gamma_distribution<result_type>::param_type& __p)
       {
 	__glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
 	while (__f != __t)
diff --git a/libstdc++-v3/include/ext/random b/libstdc++-v3/include/ext/random
index adf8a241187c..79ee5994a3a5 100644
--- a/libstdc++-v3/include/ext/random
+++ b/libstdc++-v3/include/ext/random
@@ -510,7 +510,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -522,7 +522,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -539,6 +539,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const param_type& __p)
 	{ this->__generate_impl(__f, __t, __urng, __p); }
 
+      /**
+       * @brief Return true if two beta distributions have the same
+       *        parameters and the sequences that would be generated
+       *        are equal.
+       */
+      friend bool
+      operator==(const beta_distribution& __d1,
+		 const beta_distribution& __d2)
+      { return __d1._M_param == __d2._M_param; }
+
       /**
        * @brief Inserts a %beta_distribution random number distribution
        * @p __x into the output stream @p __os.
@@ -579,17 +589,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       param_type _M_param;
     };
 
-  /**
-   * @brief Return true if two beta distributions have the same
-   *        parameters and the sequences that would be generated
-   *        are equal.
-   */
-  template<typename _RealType>
-    inline bool
-    operator==(const __gnu_cxx::beta_distribution<_RealType>& __d1,
-	       const __gnu_cxx::beta_distribution<_RealType>& __d2)
-    { return __d1.param() == __d2.param(); }
-
   /**
    * @brief Return true if two beta distributions are different.
    */
@@ -809,7 +808,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _UniformRandomNumberGenerator>
 	result_type
 	operator()(_UniformRandomNumberGenerator& __urng)
-	{ return this->operator()(__urng, this->param()); }
+	{ return this->operator()(__urng, _M_param); }
 
       template<typename _UniformRandomNumberGenerator>
 	result_type
@@ -821,7 +820,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ return this->__generate_impl(__f, __t, __urng, this->param()); }
+	{ return this->__generate_impl(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -1073,7 +1072,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -1098,7 +1097,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const rice_distribution& __d1,
 		 const rice_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_ndx == __d2._M_ndx
 		&& __d1._M_ndy == __d2._M_ndy); }
 
@@ -1296,7 +1295,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -1321,7 +1320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const nakagami_distribution& __d1,
 		 const nakagami_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_gd == __d2._M_gd); }
 
       /**
@@ -1532,7 +1531,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -1557,7 +1556,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const pareto_distribution& __d1,
 		 const pareto_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_ud == __d2._M_ud); }
 
       /**
@@ -1774,7 +1773,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -1799,7 +1798,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const k_distribution& __d1,
 		 const k_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_gd1 == __d2._M_gd1
 		&& __d1._M_gd2 == __d2._M_gd2); }
 
@@ -2006,7 +2005,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -2031,7 +2030,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const arcsine_distribution& __d1,
 		 const arcsine_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_ud == __d2._M_ud); }
 
       /**
@@ -2241,7 +2240,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	void
 	__generate(_ForwardIterator __f, _ForwardIterator __t,
 		   _UniformRandomNumberGenerator& __urng)
-	{ this->__generate(__f, __t, __urng, this->param()); }
+	{ this->__generate(__f, __t, __urng, _M_param); }
 
       template<typename _ForwardIterator,
 	       typename _UniformRandomNumberGenerator>
@@ -2266,7 +2265,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend bool
       operator==(const hoyt_distribution& __d1,
 		 const hoyt_distribution& __d2)
-      { return (__d1.param() == __d2.param()
+      { return (__d1._M_param == __d2._M_param
 		&& __d1._M_ad == __d2._M_ad
 		&& __d1._M_ed == __d2._M_ed); }
 
-- 
GitLab