diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-11-02 10:06:08 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-11-02 10:06:08 +0000 |
commit | 2350caacdc2ca207092ee12f7c605ae9dc192763 (patch) | |
tree | 48af547c3cc847618ee46d294950ca480613b916 | |
parent | 3aa6ac67f5f7d3a6aabce9ada30e99e2a82c0114 (diff) | |
download | gcc-2350caacdc2ca207092ee12f7c605ae9dc192763.tar.gz |
2011-11-02 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/50951
* include/bits/random.tcc (operator<<(basic_ostream<>&,
const mersenne_twister_engine<>&): Output _M_p too.
(operator<<(basic_ostream<>&, const
subtract_with_carry_engine<>&): Likewise.
(operator>>(basic_istream<>&, mersenne_twister_engine<>&):
Reload it.
(operator>>(basic_istream<>&, subtract_with_carry_engine<>&):
Likewise.
* include/bits/random.h (mersenne_twister_engine<>::operator==):
Compare _M_p too.
(subtract_with_carry_engine<>::operator==): Compare _M_carry
and _M_p too.
(shuffle_order_engine<>::operator==): Compare _M_v(s) and _M_y too.
* testsuite/26_numerics/random/independent_bits_engine/
operators/serialize.cc: Extend.
* testsuite/26_numerics/random/subtract_with_carry_engine/
operators/serialize.cc: Likewise.
* testsuite/26_numerics/random/discard_block_engine/
operators/serialize.cc: Likewise.
* testsuite/26_numerics/random/mersenne_twister_engine/
operators/serialize.cc: Likewise.
* testsuite/26_numerics/random/linear_congruential_engine/
operators/serialize.cc: Likewise.
* testsuite/26_numerics/random/shuffle_order_engine/
operators/serialize.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@180764 138bc75d-0d04-0410-961f-82ee72b054a4
9 files changed, 139 insertions, 19 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9f6c755cd6a..82a0b911412 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,32 @@ +2011-11-02 Paolo Carlini <paolo.carlini@oracle.com> + + PR libstdc++/50951 + * include/bits/random.tcc (operator<<(basic_ostream<>&, + const mersenne_twister_engine<>&): Output _M_p too. + (operator<<(basic_ostream<>&, const + subtract_with_carry_engine<>&): Likewise. + (operator>>(basic_istream<>&, mersenne_twister_engine<>&): + Reload it. + (operator>>(basic_istream<>&, subtract_with_carry_engine<>&): + Likewise. + * include/bits/random.h (mersenne_twister_engine<>::operator==): + Compare _M_p too. + (subtract_with_carry_engine<>::operator==): Compare _M_carry + and _M_p too. + (shuffle_order_engine<>::operator==): Compare _M_v(s) and _M_y too. + * testsuite/26_numerics/random/independent_bits_engine/ + operators/serialize.cc: Extend. + * testsuite/26_numerics/random/subtract_with_carry_engine/ + operators/serialize.cc: Likewise. + * testsuite/26_numerics/random/discard_block_engine/ + operators/serialize.cc: Likewise. + * testsuite/26_numerics/random/mersenne_twister_engine/ + operators/serialize.cc: Likewise. + * testsuite/26_numerics/random/linear_congruential_engine/ + operators/serialize.cc: Likewise. + * testsuite/26_numerics/random/shuffle_order_engine/ + operators/serialize.cc: Likewise. + 2011-11-02 Benjamin Kosnik <bkoz@redhat.com> * include/bits/c++config: Add tr2 to versioned namespaces. diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index 7c66d633863..d109224d1bf 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -491,7 +491,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION friend bool operator==(const mersenne_twister_engine& __lhs, const mersenne_twister_engine& __rhs) - { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); } + { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x) + && __lhs._M_p == __rhs._M_p); } /** * @brief Inserts the current state of a % mersenne_twister_engine @@ -705,7 +706,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION friend bool operator==(const subtract_with_carry_engine& __lhs, const subtract_with_carry_engine& __rhs) - { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); } + { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x) + && __lhs._M_carry == __rhs._M_carry + && __lhs._M_p == __rhs._M_p); } /** * @brief Inserts the current state of a % subtract_with_carry_engine @@ -1370,7 +1373,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION friend bool operator==(const shuffle_order_engine& __lhs, const shuffle_order_engine& __rhs) - { return __lhs._M_b == __rhs._M_b; } + { return (__lhs._M_b == __rhs._M_b + && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v) + && __lhs._M_y == __rhs._M_y); } /** * @brief Inserts the current state of a %shuffle_order_engine random diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc index 0e74848ff3c..8936a62316a 100644 --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -471,9 +471,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); __os.fill(__space); - for (size_t __i = 0; __i < __n - 1; ++__i) + for (size_t __i = 0; __i < __n; ++__i) __os << __x._M_x[__i] << __space; - __os << __x._M_x[__n - 1]; + __os << __x._M_p; __os.flags(__flags); __os.fill(__fill); @@ -498,6 +498,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION for (size_t __i = 0; __i < __n; ++__i) __is >> __x._M_x[__i]; + __is >> __x._M_p; __is.flags(__flags); return __is; @@ -627,7 +628,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION for (size_t __i = 0; __i < __r; ++__i) __os << __x._M_x[__i] << __space; - __os << __x._M_carry; + __os << __x._M_carry << __space << __x._M_p; __os.flags(__flags); __os.fill(__fill); @@ -649,6 +650,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION for (size_t __i = 0; __i < __r; ++__i) __is >> __x._M_x[__i]; __is >> __x._M_carry; + __is >> __x._M_p; __is.flags(__flags); return __is; diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc index 7aec649c03b..4249d975a82 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -46,6 +46,20 @@ test01() str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc index 332931addfa..32a5157608c 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -44,6 +44,20 @@ test01() str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc index 8b67e5f3a33..a83b22ef651 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -33,15 +33,29 @@ test01() bool test __attribute__((unused)) = true; std::stringstream str; - std::minstd_rand0 a; - std::minstd_rand0 b; + std::minstd_rand0 u; + std::minstd_rand0 v; - a(); // advance - str << a; - VERIFY( !(a == b) ); + u(); // advance + str << u; + VERIFY( !(u == v) ); - str >> b; - VERIFY( a == b ); + str >> v; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc index 03fb8b04fa1..7c90e3d390f 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -47,6 +47,20 @@ test01() str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc index 578e4959371..c7b15d1ba15 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -46,6 +46,20 @@ test01() str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc index e4129fc8df5..1e2e53ac593 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -43,6 +43,20 @@ test01() str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() |