This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] libstdc++/37986 (cont)


Hi,

should be Ok for now; tested x86_64-linux, committed to mainline.

Paolo.

//////////////////////
2008-11-12  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/37986 (cont)
	* include/tr1_impl/random (struct _Adaptor): Use only remove_reference
	on _Engine.
	(struct _Adaptor<_Engine*, _Distribution>): Add.
	* testsuite/tr1/5_numerical_facilities/random/variate_generator/
	37986.cc: Extend.
Index: include/tr1_impl/random
===================================================================
*** include/tr1_impl/random	(revision 141783)
--- include/tr1_impl/random	(working copy)
*************** _GLIBCXX_BEGIN_NAMESPACE_TR1
*** 79,89 ****
      template<typename _Engine, typename _Distribution>
        struct _Adaptor
        { 
! 	typedef typename remove_reference<
! 	  typename remove_pointer<_Engine>::type>::type _BEngine;
! 
! 	typedef typename _BEngine::result_type       _Engine_result_type;
! 	typedef typename _Distribution::input_type   result_type;
  
        public:
  	_Adaptor(const _Engine& __g)
--- 79,87 ----
      template<typename _Engine, typename _Distribution>
        struct _Adaptor
        { 
! 	typedef typename remove_reference<_Engine>::type _BEngine;
! 	typedef typename _BEngine::result_type           _Engine_result_type;
! 	typedef typename _Distribution::input_type       result_type;
  
        public:
  	_Adaptor(const _Engine& __g)
*************** _GLIBCXX_BEGIN_NAMESPACE_TR1
*** 149,154 ****
--- 147,215 ----
        private:
  	_Engine _M_g;
        };
+ 
+     // Specialization for _Engine*.
+     template<typename _Engine, typename _Distribution>
+       struct _Adaptor<_Engine*, _Distribution>
+       {
+ 	typedef typename _Engine::result_type      _Engine_result_type;
+ 	typedef typename _Distribution::input_type result_type;
+ 
+       public:
+ 	_Adaptor(_Engine* __g)
+ 	: _M_g(__g) { }
+ 
+ 	result_type
+ 	min() const
+ 	{
+ 	  result_type __return_value;
+ 	  if (is_integral<_Engine_result_type>::value
+ 	      && is_integral<result_type>::value)
+ 	    __return_value = _M_g->min();
+ 	  else
+ 	    __return_value = result_type(0);
+ 	  return __return_value;
+ 	}
+ 
+ 	result_type
+ 	max() const
+ 	{
+ 	  result_type __return_value;
+ 	  if (is_integral<_Engine_result_type>::value
+ 	      && is_integral<result_type>::value)
+ 	    __return_value = _M_g->max();
+ 	  else if (!is_integral<result_type>::value)
+ 	    __return_value = result_type(1);
+ 	  else
+ 	    __return_value = std::numeric_limits<result_type>::max() - 1;
+ 	  return __return_value;
+ 	}
+ 
+ 	result_type
+ 	operator()()
+ 	{
+ 	  result_type __return_value;
+ 	  if (is_integral<_Engine_result_type>::value
+ 	      && is_integral<result_type>::value)
+ 	    __return_value = (*_M_g)();
+ 	  else if (!is_integral<_Engine_result_type>::value
+ 		   && !is_integral<result_type>::value)
+ 	    __return_value = result_type((*_M_g)() - _M_g->min())
+ 	      / result_type(_M_g->max() - _M_g->min());
+ 	  else if (is_integral<_Engine_result_type>::value
+ 		   && !is_integral<result_type>::value)
+ 	    __return_value = result_type((*_M_g)() - _M_g->min())
+ 	      / result_type(_M_g->max() - _M_g->min() + result_type(1));
+ 	  else
+ 	    __return_value = ((((*_M_g)() - _M_g->min()) 
+ 			       / (_M_g->max() - _M_g->min()))
+ 			      * std::numeric_limits<result_type>::max());
+ 	  return __return_value;
+ 	}
+ 
+       private:
+ 	_Engine* _M_g;
+       };
    } // namespace __detail
  
    /**
Index: testsuite/tr1/5_numerical_facilities/random/variate_generator/37986.cc
===================================================================
*** testsuite/tr1/5_numerical_facilities/random/variate_generator/37986.cc	(revision 141783)
--- testsuite/tr1/5_numerical_facilities/random/variate_generator/37986.cc	(working copy)
*************** void test01()
*** 42,45 ****
--- 42,49 ----
      std::tr1::mt19937*,
      std::tr1::uniform_real<double>
      > g3(&mt, dist);
+ 
+   g1();
+   g2();
+   g3();
  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]