1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: no-localization |
10 | |
11 | // <random> |
12 | |
13 | // template<class RealType = double> |
14 | // class piecewise_constant_distribution |
15 | |
16 | // template <class charT, class traits> |
17 | // basic_ostream<charT, traits>& |
18 | // operator<<(basic_ostream<charT, traits>& os, |
19 | // const piecewise_constant_distribution& x); |
20 | // |
21 | // template <class charT, class traits> |
22 | // basic_istream<charT, traits>& |
23 | // operator>>(basic_istream<charT, traits>& is, |
24 | // piecewise_constant_distribution& x); |
25 | |
26 | #include <random> |
27 | #include <sstream> |
28 | #include <cassert> |
29 | |
30 | #include "test_macros.h" |
31 | |
32 | int main(int, char**) |
33 | { |
34 | { |
35 | typedef std::piecewise_constant_distribution<> D; |
36 | double b[] = {10, 14, 16, 17}; |
37 | double p[] = {25, 62.5, 12.5}; |
38 | const std::size_t Np = sizeof(p) / sizeof(p[0]); |
39 | D d1(b, b+Np+1, p); |
40 | std::ostringstream os; |
41 | os << d1; |
42 | std::istringstream is(os.str()); |
43 | D d2; |
44 | is >> d2; |
45 | assert(d1 == d2); |
46 | } |
47 | |
48 | return 0; |
49 | } |
50 | |