* [v3] libstdc++/37986 (cont)
@ 2008-11-12 12:03 Paolo Carlini
0 siblings, 0 replies; only message in thread
From: Paolo Carlini @ 2008-11-12 12:03 UTC (permalink / raw)
To: Gcc Patch List; +Cc: libstdc++
[-- Attachment #1: Type: text/plain, Size: 103 bytes --]
Hi,
should be Ok for now; tested x86_64-linux, committed to mainline.
Paolo.
//////////////////////
[-- Attachment #2: CL_37986_a --]
[-- Type: text/plain, Size: 302 bytes --]
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.
[-- Attachment #3: patch_37986_a --]
[-- Type: text/plain, Size: 3572 bytes --]
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();
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-11-12 10:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-12 12:03 [v3] libstdc++/37986 (cont) Paolo Carlini
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).