From bfe3e83159fa545f90a81e81321a77ca9f6fd6c0 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 26 Jun 2006 03:08:48 +0000 Subject: random (operator<<(std::basic_ostream<>&, const linear_congruential<>&), [...]): Redo per TR1 specs; move out of line... 2006-06-25 Paolo Carlini * include/tr1/random (operator<<(std::basic_ostream<>&, const linear_congruential<>&), operator>>(std::basic_istream<>&, linear_congruential<>&), operator<<(std::basic_ostream<>&, const mersenne_twister<>&), operator>>(std::basic_istream<>&, mersenne_twister<>&), operator<<(std::basic_ostream<>&, const subtract_with_carry<>&), operator>>(std::basic_istream<>&, subtract_with_carry<>&), operator<<(std::basic_ostream<>&, const discard_block<>&), operator>>(std::basic_istream<>&, discard_block<>&), operator<<(std::basic_ostream<>&, const xor_combine<>&), operator>>(std::basic_istream<>&, xor_combine<>&), operator<<(std::basic_ostream<>&, const uniform_int<>&), operator>>(std::basic_istream<>&, uniform_int<>&), operator<<(std::basic_ostream<>&, const bernoulli_distribution&), operator<<(std::basic_ostream<>&, const geometric_distribution<>&), operator<<(std::basic_ostream<>&, const uniform_real<>&), operator>>(std::basic_istream<>&, uniform_real<>&), operator<<(std::basic_ostream<>&, const exponential_distribution<>&), operator<<(std::basic_ostream<>&, const normal_distribution<>&), operator>>(std::basic_istream<>&, normal_distribution<>&)): Redo per TR1 specs; move out of line... * include/tr1/random.tcc: ... here. From-SVN: r115003 --- libstdc++-v3/ChangeLog | 24 +++ libstdc++-v3/include/tr1/random | 350 +++++++++++++++++++++++---------- libstdc++-v3/include/tr1/random.tcc | 373 ++++++++++++++++++++++++++++++++++++ 3 files changed, 641 insertions(+), 106 deletions(-) (limited to 'libstdc++-v3') diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6979a43..359e79d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,27 @@ +2006-06-25 Paolo Carlini + + * include/tr1/random (operator<<(std::basic_ostream<>&, + const linear_congruential<>&), operator>>(std::basic_istream<>&, + linear_congruential<>&), operator<<(std::basic_ostream<>&, + const mersenne_twister<>&), operator>>(std::basic_istream<>&, + mersenne_twister<>&), operator<<(std::basic_ostream<>&, + const subtract_with_carry<>&), operator>>(std::basic_istream<>&, + subtract_with_carry<>&), operator<<(std::basic_ostream<>&, + const discard_block<>&), operator>>(std::basic_istream<>&, + discard_block<>&), operator<<(std::basic_ostream<>&, + const xor_combine<>&), operator>>(std::basic_istream<>&, + xor_combine<>&), operator<<(std::basic_ostream<>&, + const uniform_int<>&), operator>>(std::basic_istream<>&, + uniform_int<>&), operator<<(std::basic_ostream<>&, + const bernoulli_distribution&), operator<<(std::basic_ostream<>&, + const geometric_distribution<>&), operator<<(std::basic_ostream<>&, + const uniform_real<>&), operator>>(std::basic_istream<>&, + uniform_real<>&), operator<<(std::basic_ostream<>&, + const exponential_distribution<>&), operator<<(std::basic_ostream<>&, + const normal_distribution<>&), operator>>(std::basic_istream<>&, + normal_distribution<>&)): Redo per TR1 specs; move out of line... + * include/tr1/random.tcc: ... here. + 2006-06-24 Paolo Carlini * include/tr1/random (class normal_distribution<>): Add. diff --git a/libstdc++-v3/include/tr1/random b/libstdc++-v3/include/tr1/random index 7eb8f67..f1a3ab2 100644 --- a/libstdc++-v3/include/tr1/random +++ b/libstdc++-v3/include/tr1/random @@ -288,6 +288,21 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * The size of the state is @f$ 1 @f$. */ template + class linear_congruential; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const linear_congruential<_UIntType, __a, __c, __m>& __lcr); + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + linear_congruential<_UIntType, __a, __c, __m>& __lcr); + + template class linear_congruential { __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) @@ -394,14 +409,16 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * Writes the textual representation of the state x(i) of x to @p __os. * * @param __os The output stream. - * @param __lcr A linear_congruential random number generator. + * @param __lcr A % linear_congruential random number generator. * @returns __os. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const linear_congruential& __lcr) - { return __os << __lcr._M_x; } + const linear_congruential<_UIntType1, __a1, __c1, + __m1>& __lcr); /** * Sets the state of the engine by reading its textual @@ -413,14 +430,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @p __is. * * @param __is The input stream. - * @param __lcr A linear_congruential random number generator. + * @param __lcr A % linear_congruential random number generator. * @returns __is. */ - template + template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - linear_congruential& __lcr) - { return __is >> __lcr._M_x; } + linear_congruential<_UIntType1, __a1, __c1, __m1>& __lcr); private: template @@ -475,6 +493,29 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) template + class mersenne_twister; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x); + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x); + + template class mersenne_twister { __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) @@ -571,15 +612,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const mersenne_twister& __x) - { - std::copy(__x._M_x, __x._M_x + state_size, - std::ostream_iterator<_UIntType>(__os, " ")); - return __os; - } + const mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); /** * Extracts the current state of a % mersenne_twister random number @@ -591,15 +631,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The input stream with the state of @p __x extracted or in * an error state. */ - template + template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - mersenne_twister& __x) - { - for (int __i = 0; __i < state_size; ++__i) - __is >> __x._M_x[__i]; - return __is; - } + mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); private: template @@ -654,6 +693,21 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @endif */ template + class subtract_with_carry; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry<_IntType, __m, __s, __r>& __x); + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry<_IntType, __m, __s, __r>& __x); + + template class subtract_with_carry { __glibcxx_class_requires(_IntType, _IntegerConcept) @@ -780,15 +834,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry& __x) - { - std::copy(__x._M_x, __x._M_x + long_lag, - std::ostream_iterator<_IntType>(__os, " ")); - return __os << __x._M_carry; - } + const subtract_with_carry<_IntType1, __m1, __s1, + __r1>& __x); /** * Extracts the current state of a % subtract_with_carry random number @@ -800,16 +851,11 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The input stream with the state of @p __x extracted or in * an error state. */ - template + template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - subtract_with_carry& __x) - { - for (int __i = 0; __i < long_lag; ++__i) - __is >> __x._M_x[__i]; - __is >> __x._M_carry; - return __is; - } + subtract_with_carry<_IntType1, __m1, __s1, __r1>& __x); private: template @@ -835,6 +881,22 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * 0 <= @p __r <= @p __p */ template + class discard_block; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discard_block<_UniformRandomNumberGenerator, + __p, __r>& __x); + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discard_block<_UniformRandomNumberGenerator, __p, __r>& __x); + + template class discard_block { // __glibcxx_class_requires(typename base_type::result_type, @@ -974,11 +1036,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const discard_block& __x) - { return __os << __x._M_b << " " << __x._M_n; } + const discard_block<_UniformRandomNumberGenerator1, + __p1, __r1>& __x); /** * Extracts the current state of a % subtract_with_carry random number @@ -990,11 +1053,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The input stream with the state of @p __x extracted or in * an error state. */ - template + template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - discard_block& __x) - { return __is >> __x._M_b >> __x._M_n; } + discard_block<_UniformRandomNumberGenerator1, + __p1, __r1>& __x); private: base_type _M_b; @@ -1027,6 +1091,26 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) */ template + class xor_combine; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x); + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x); + + template class xor_combine { // __glibcxx_class_requires(typename _UniformRandomNumberGenerator1:: @@ -1146,11 +1230,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const xor_combine& __x) - { return __os << __x.base1() << " " << __x.base2(); } + const xor_combine<_UniformRandomNumberGenerator11, __s11, + _UniformRandomNumberGenerator21, __s21>& __x); /** * Extracts the current state of a %xor_combine random number @@ -1162,11 +1248,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The input stream with the state of @p __x extracted or in * an error state. */ - template + template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - xor_combine& __x) - { return __is >> __x._M_b1 >> __x._M_b2; } + xor_combine<_UniformRandomNumberGenerator11, __s11, + _UniformRandomNumberGenerator21, __s21>& __x); private: base1_type _M_b1; @@ -1283,6 +1371,19 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * probability throughout the range. */ template + class uniform_int; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int<_IntType>& __x); + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int<_IntType>& __x); + + template class uniform_int { __glibcxx_class_requires(_IntType, _IntegerConcept) @@ -1355,25 +1456,24 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_int& __x) - { return __os << __x.min() << " " << __x.max(); } + const uniform_int<_IntType1>& __x); /** * Extracts a %unform_int random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %uniform_int random number generator engine. + * @param __x A %uniform_int random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ - template + template friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, uniform_int& __u) - { return __is >> __u._M_min >> __u._M_max; } + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int<_IntType1>& __x); private: _IntType _M_min; @@ -1387,6 +1487,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * Generates a sequence of true and false values with likelihood @f$ p @f$ * that true will come up and @f$ (1 - p) @f$ that false will appear. */ + class bernoulli_distribution; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const bernoulli_distribution& __x); + class bernoulli_distribution { public: @@ -1447,23 +1554,22 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const bernoulli_distribution& __x) - { return __os << __x.p(); } + const bernoulli_distribution& __x); /** * Extracts a %bernoulli_distribution random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %bernoulli_distribution random number generator engine. + * @param __x A %bernoulli_distribution random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - bernoulli_distribution& __u) - { return __is >> __u._M_p; } + bernoulli_distribution& __x) + { return __is >> __x._M_p; } protected: double _M_p; @@ -1478,6 +1584,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * distribution. */ template + class geometric_distribution; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType, _RealType>& __x); + + template class geometric_distribution { public: @@ -1519,28 +1634,28 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const geometric_distribution& __x) - { return __os << __x.p(); } + const geometric_distribution<_IntType1, _RealType1>& __x); /** * Extracts a %geometric_distribution random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %geometric_distribution random number generator engine. + * @param __x A %geometric_distribution random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - geometric_distribution& __u) + geometric_distribution& __x) { - __is >> __u._M_p; - __u._M_log_p = std::log(__u._M_p); + __is >> __x._M_p; + __x._M_log_p = std::log(__x._M_p); return __is; } @@ -1565,6 +1680,19 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * deliver number in the range [0, 1). */ template + class uniform_real; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_real<_RealType>& __x); + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_real<_RealType>& __x); + + template class uniform_real { public: @@ -1613,26 +1741,24 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_real& __x) - { return __os << __x.min() << " " << __x.max(); } + const uniform_real<_RealType1>& __x); /** * Extracts a %unform_real random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %uniform_real random number generator engine. + * @param __x A %uniform_real random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ - template + template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - uniform_real& __u) - { return __is >> __u._M_min >> __u._M_max; } + uniform_real<_RealType1>& __x); protected: _RealType _M_min; @@ -1656,6 +1782,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * */ template + class exponential_distribution; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType>& __x); + + template class exponential_distribution { public: @@ -1705,26 +1839,25 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const exponential_distribution& __x) - { return __os << __x.lambda(); } + const exponential_distribution<_RealType1>& __x); /** * Extracts a %exponential_distribution random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %exponential_distribution random number generator engine. + * @param __x A %exponential_distribution random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - exponential_distribution& __u) - { return __is >> __u._M_lambda; } + exponential_distribution& __x) + { return __is >> __x._M_lambda; } private: result_type _M_lambda; @@ -1739,6 +1872,19 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * e^{- \frac{{x - mean}^ {2}}{2 \sigma ^ {2}} } @f$. */ template + class normal_distribution; + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType>& __x); + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RealType>& __x); + + template class normal_distribution { public: @@ -1794,32 +1940,24 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template + template friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const normal_distribution& __x) - { - return __os << __x.mean() << " " << __x.sigma() - << " " << __x._M_saved << " " << __x._M_saved_available; - } + const normal_distribution<_RealType1>& __x); /** * Extracts a %normal_distribution random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %normal_distribution random number generator engine. + * @param __x A %normal_distribution random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ - template + template friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - normal_distribution& __u) - { - return __is >> __u._M_mean >> __u._M_sigma - >> __u._M_saved >> __u._M_saved_available; - } + normal_distribution<_RealType1>& __x); private: result_type _M_mean; diff --git a/libstdc++-v3/include/tr1/random.tcc b/libstdc++-v3/include/tr1/random.tcc index d4f2464..562ea9e 100644 --- a/libstdc++-v3/include/tr1/random.tcc +++ b/libstdc++-v3/include/tr1/random.tcc @@ -94,6 +94,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) __mod(_Tp __x) { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); } + // See N1822. + template + struct _Max_digits10 + { + static const std::streamsize __value = + 2 + std::numeric_limits<_RealType>::digits * 3010/10000; + }; + } // namespace _Private @@ -167,6 +175,40 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) return _M_x; } + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const linear_congruential<_UIntType, __a, __c, __m>& __lcr) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__os.widen(' ')); + + __os << __lcr._M_x; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + linear_congruential<_UIntType, __a, __c, __m>& __lcr) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec); + + __is >> __lcr._M_x; + + __is.flags(__flags); + return __is; + } + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__space); + + for (int __i = 0; __i < __n - 1; ++__i) + __os << __x._M_x[__i] << __space; + __os << __x._M_x[__n - 1]; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + for (int __i = 0; __i < __n; ++__i) + __is >> __x._M_x[__i]; + + __is.flags(__flags); + return __is; + } + template void @@ -332,6 +418,45 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) return __xi; } + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry<_IntType, __m, __s, __r>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__space); + + for (int __i = 0; __i < __r; ++__i) + __os << __x._M_x[__i] << __space; + __os << __x._M_carry; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry<_IntType, __m, __s, __r>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + for (int __i = 0; __i < __r; ++__i) + __is >> __x._M_x[__i]; + __is >> __x._M_carry; + + __is.flags(__flags); + return __is; + } + template typename discard_block<_UniformRandomNumberGenerator, @@ -352,6 +477,215 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) return _M_b(); } + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discard_block<_UniformRandomNumberGenerator, + __p, __r>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__space); + + __os << __x._M_b << __space << __x._M_n; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discard_block<_UniformRandomNumberGenerator, __p, __r>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + __is >> __x._M_b >> __x._M_n; + + __is.flags(__flags); + return __is; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__space); + + __os << __x.base1() << __space << __x.base2(); + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::skipws); + + __is >> __x._M_b1 >> __x._M_b2; + + __is.flags(__flags); + return __is; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int<_IntType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__space); + + __os << __x.min() << __space << __x.max(); + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int<_IntType>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + __is >> __x._M_min >> __x._M_max; + + __is.flags(__flags); + return __is; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const bernoulli_distribution& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(_Private::_Max_digits10::__value); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType, _RealType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(_Private::_Max_digits10<_RealType>::__value); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_real<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__space); + __os.precision(_Private::_Max_digits10<_RealType>::__value); + + __os << __x.min() << __space << __x.max(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_real<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::skipws); + + __is >> __x._M_min >> __x._M_max; + + __is.flags(__flags); + return __is; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(_Private::_Max_digits10<_RealType>::__value); + + __os << __x.lambda(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + /** * Classic Box-Muller method. @@ -394,5 +728,44 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) return __ret * _M_sigma + _M_mean; } + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__space); + __os.precision(_Private::_Max_digits10<_RealType>::__value); + + __os << __x.mean() << __space + << __x.sigma() << __space + << __x._M_saved << __space + << __x._M_saved_available; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + __is >> __x._M_mean >> __x._M_sigma + >> __x._M_saved >> __x._M_saved_available; + + __is.flags(__flags); + return __is; + } + _GLIBCXX_END_NAMESPACE } -- cgit v1.1