| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-require-cstdint "" } |
| 3 |
// |
| 4 |
// 2009-08-14 Edward M. Smith-Rowland <[email protected]> |
| 5 |
// |
| 6 |
// Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 7 |
// |
| 8 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 9 |
// software; you can redistribute it and/or modify it under the |
| 10 |
// terms of the GNU General Public License as published by the |
| 11 |
// Free Software Foundation; either version 3, or (at your option) |
| 12 |
// any later version. |
| 13 |
// |
| 14 |
// This library is distributed in the hope that it will be useful, |
| 15 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
// GNU General Public License for more details. |
| 18 |
// |
| 19 |
// You should have received a copy of the GNU General Public License along |
| 20 |
// with this library; see the file COPYING3. If not see |
| 21 |
// <http://www.gnu.org/licenses/>. |
| 22 |
|
| 23 |
// 26.4.8.4.1 Class template normal_distribution [rand.dist.norm.normal] |
| 24 |
// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] |
| 25 |
|
| 26 |
#include <random> |
| 27 |
#include <sstream> |
| 28 |
#include <testsuite_hooks.h> |
| 29 |
|
| 30 |
void |
| 31 |
test01() |
| 32 |
{ |
| 33 |
std::stringstream str; |
| 34 |
std::normal_distribution<double> u(5.0, 2.0), v; |
| 35 |
std::minstd_rand0 rng; |
| 36 |
|
| 37 |
u(rng); // advance |
| 38 |
str << u; |
| 39 |
|
| 40 |
str >> v; |
| 41 |
VERIFY( u == v ); |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
test_pr105502() |
| 46 |
{ |
| 47 |
// PR libstdc++/105502 std::normal_distribution deserialization issue |
| 48 |
std::stringstream str; |
| 49 |
std::normal_distribution<> d{1, 2}, d2; |
| 50 |
std::minstd_rand0 g; |
| 51 |
str << d; |
| 52 |
VERIFY( str ); |
| 53 |
str >> d2; |
| 54 |
VERIFY( str ); |
| 55 |
VERIFY( d == d2 ); |
| 56 |
|
| 57 |
(void) d(g); // sets d._M_saved_available = true |
| 58 |
str.str(""); |
| 59 |
str.clear(); |
| 60 |
str << d; |
| 61 |
VERIFY( str ); |
| 62 |
str >> d2; |
| 63 |
VERIFY( str ); |
| 64 |
VERIFY( d == d2 ); |
| 65 |
|
| 66 |
(void) d(g); // sets d._M_saved_available = false |
| 67 |
str.str(""); |
| 68 |
str.clear(); |
| 69 |
str << d; |
| 70 |
VERIFY( str ); |
| 71 |
str >> d2; |
| 72 |
VERIFY( str ); |
| 73 |
VERIFY( d == d2 ); |
| 74 |
} |
| 75 |
|
| 76 |
int main() |
| 77 |
{ |
| 78 |
test01(); |
| 79 |
test_pr105502(); |
| 80 |
} |