Debian Codegraph @

libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc

raw
1 // { dg-do run { target c++11 } }
2 #include <random>
3 #include <testsuite_hooks.h>
4
5 // PR 107466 - invalid -Wnarrowing error with std::subtract_with_carry_engine
6
7 // LWG 3809. Is std::subtract_with_carry_engine<uint16_t> supposed to work?
8 void
9 test_lwg3809()
10 {
11 // It should be possible to construct this engine with a 16-bit result_type:
12 std::subtract_with_carry_engine<uint16_t, 12, 5, 12> s16;
13 std::subtract_with_carry_engine<uint32_t, 12, 5, 12> s32;
14 // It should have been seeded with the same sequence as the 32-bit version
15 // and produce random numbers in the same range, [0, 1<<12).
16 for (int i = 0; i < 10; ++i)
17 VERIFY( s16() == s32() );
18 // The default seed should be usable without truncation to uint16_t:
19 s16.seed();
20 s32.seed();
21 for (int i = 0; i < 10; ++i)
22 VERIFY( s16() == s32() );
23 s16.seed(101);
24 s32.seed(101);
25 for (int i = 0; i < 10; ++i)
26 VERIFY( s16() == s32() );
27 }
28
29 // LWG 4014. LWG 3809 changes behavior of some existing code
30 void
31 test_lwg4014()
32 {
33 std::ranlux48_base g(-1U + 1LL);
34 VERIFY( g() == 22575453646312 );
35 }
36
37 int main()
38 {
39 test_lwg3809();
40 test_lwg4014();
41 }