diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-05-06 21:37:47 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-05-06 23:54:09 +0100 |
commit | 42991a911685a419794c47eba640d35ca60c2d99 (patch) | |
tree | 8cf0c1c4a117fff9ce2c1d90b96480ee65d55d67 /libstdc++-v3 | |
parent | 909ef4e2727ddc50a32d6ad379a1f1ccc1043c6a (diff) | |
download | gcc-42991a911685a419794c47eba640d35ca60c2d99.zip gcc-42991a911685a419794c47eba640d35ca60c2d99.tar.gz gcc-42991a911685a419794c47eba640d35ca60c2d99.tar.bz2 |
libstdc++: Simplify std::normal_distribution equality operator
libstdc++-v3/ChangeLog:
* include/bits/random.tcc (operator==): Only check
normal_distribution::_M_saved_available once.
* testsuite/26_numerics/random/normal_distribution/operators/equal.cc:
Check equality after state changes.
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
lineno.
Diffstat (limited to 'libstdc++-v3')
3 files changed, 22 insertions, 10 deletions
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc index 87a16a2..cb1d367 100644 --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -1907,15 +1907,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if (__d1._M_param == __d2._M_param && __d1._M_saved_available == __d2._M_saved_available) - { - if (__d1._M_saved_available - && __d1._M_saved == __d2._M_saved) - return true; - else if(!__d1._M_saved_available) - return true; - else - return false; - } + return __d1._M_saved_available ? __d1._M_saved == __d2._M_saved : true; else return false; } diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/equal.cc index a343523..81534e9 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/equal.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/equal.cc @@ -34,8 +34,28 @@ test01() VERIFY( !(u == v) ); } +void +test02() +{ + std::normal_distribution<double> u(5.0, 2.0), v(u); + VERIFY( u == v ); + u.reset(); + VERIFY( u == v ); + + std::minstd_rand0 g1, g2; + (void) u(g1); // u._M_saved_available = true + VERIFY( !(u == v) ); + (void) v(g2); // v._M_saved_available = true + VERIFY( u == v ); + u.reset(); // u._M_saved_available = false + VERIFY( !(u == v) ); + v.reset(); // v._M_saved_available = false + VERIFY( u == v ); +} + int main() { test01(); + test02(); return 0; } diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc index 3ab9c44..c58f480 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc @@ -12,4 +12,4 @@ auto x = std::generate_canonical<std::size_t, // { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 169 } -// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3356 } +// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3348 } |