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 | // <random> |
10 | |
11 | // template<class RealType = double> |
12 | // class uniform_real_distribution |
13 | |
14 | // explicit uniform_real_distribution(RealType a = 0.0, |
15 | // RealType b = 1.0); // before C++20 |
16 | // uniform_real_distribution() : uniform_real_distribution(0.0) {} // C++20 |
17 | // explicit uniform_real_distribution(RealType a, RealType b = 1.0); // C++20 |
18 | |
19 | #include <random> |
20 | #include <cassert> |
21 | |
22 | #include "test_macros.h" |
23 | #if TEST_STD_VER >= 11 |
24 | #include "make_implicit.h" |
25 | #include "test_convertible.h" |
26 | #endif |
27 | |
28 | template <class T> |
29 | void test_implicit() { |
30 | #if TEST_STD_VER >= 11 |
31 | typedef std::uniform_real_distribution<T> D; |
32 | static_assert(test_convertible<D>(), "" ); |
33 | assert(D(0) == make_implicit<D>()); |
34 | static_assert(!test_convertible<D, T>(), "" ); |
35 | static_assert(!test_convertible<D, T, T>(), "" ); |
36 | #endif |
37 | } |
38 | |
39 | int main(int, char**) |
40 | { |
41 | { |
42 | typedef std::uniform_real_distribution<> D; |
43 | D d; |
44 | assert(d.a() == 0.0); |
45 | assert(d.b() == 1.0); |
46 | } |
47 | { |
48 | typedef std::uniform_real_distribution<> D; |
49 | D d(-6.5); |
50 | assert(d.a() == -6.5); |
51 | assert(d.b() == 1.0); |
52 | } |
53 | { |
54 | typedef std::uniform_real_distribution<> D; |
55 | D d(-6.9, 106.1); |
56 | assert(d.a() == -6.9); |
57 | assert(d.b() == 106.1); |
58 | } |
59 | |
60 | test_implicit<float>(); |
61 | test_implicit<double>(); |
62 | |
63 | return 0; |
64 | } |
65 | |