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