1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class UIntType, UIntType a, UIntType c, UIntType m>
12 // class linear_congruential_engine
15 // engine characteristics
16 // static constexpr result_type multiplier = a;
17 // static constexpr result_type increment = c;
18 // static constexpr result_type modulus = m;
19 // static constexpr result_type min() { return c == 0u ? 1u: 0u;}
20 // static constexpr result_type max() { return m - 1u;}
21 // static constexpr result_type default_seed = 1u;
24 #include <type_traits>
27 #include "test_macros.h"
30 void where(const T
&) {}
32 template <class T
, T a
, T c
, T m
>
36 typedef std::linear_congruential_engine
<T
, a
, c
, m
> LCE
;
37 typedef typename
LCE::result_type result_type
;
38 static_assert((LCE::multiplier
== a
), "");
39 static_assert((LCE::increment
== c
), "");
40 static_assert((LCE::modulus
== m
), "");
41 #if TEST_STD_VER >= 11
42 static_assert((LCE::min() == (c
== 0u ? 1u: 0u)), "");
44 assert((LCE::min() == (c
== 0u ? 1u: 0u)));
48 TEST_MSVC_DIAGNOSTIC_IGNORED(4310) // cast truncates constant value
50 #if TEST_STD_VER >= 11
51 static_assert((LCE::max() == result_type(m
- 1u)), "");
53 assert((LCE::max() == result_type(m
- 1u)));
58 static_assert((LCE::default_seed
== 1), "");
59 where(LCE::multiplier
);
60 where(LCE::increment
);
62 where(LCE::default_seed
);
72 const T
M(static_cast<T
>(-1));
74 test1
<T
, 0, M
-2, M
>();
75 test1
<T
, 0, M
-1, M
>();
76 test1
<T
, M
-2, 0, M
>();
77 test1
<T
, M
-2, M
-2, M
>();
78 test1
<T
, M
-2, M
-1, M
>();
79 test1
<T
, M
-1, 0, M
>();
80 test1
<T
, M
-1, M
-2, M
>();
81 test1
<T
, M
-1, M
-1, M
>();
86 test
<unsigned short>();
88 test
<unsigned long>();
89 test
<unsigned long long>();