]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed_seq2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 26_numerics / random / mersenne_twister_engine / cons / seed_seq2.cc
1 // Copyright (C) 2018-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do run { target c++11 } }
19 // { dg-require-cstdint "" }
20
21 #include <random>
22 #include <testsuite_hooks.h>
23
24 template<typename T>
25 struct seed_seq
26 {
27 using result_type = unsigned;
28
29 seed_seq() { }
30
31 template<class U>
32 seed_seq(std::initializer_list<U>) { }
33
34 template<class InputIterator>
35 seed_seq(InputIterator, InputIterator) { }
36
37 template<class RandomAccessIterator>
38 void generate(RandomAccessIterator first, RandomAccessIterator last)
39 {
40 called = true;
41 if (first != last)
42 *first = 42;
43 }
44
45 size_t size() const { called = true; return 1; }
46
47 template<class OutputIterator>
48 void param(OutputIterator dest) const { called = true; dest = 42; }
49
50 // Prevents this type being considered as a seed sequence when
51 // T is convertible to the engine's result_type:
52 operator T() const noexcept { return T(); }
53
54 mutable bool called = false;
55 };
56
57 using engine_type
58 = std::mersenne_twister_engine<
59 unsigned long, 32, 624, 397, 31,
60 0x9908b0dful, 11,
61 0xfffffffful, 7,
62 0x9d2c5680ul, 15,
63 0xefc60000ul, 18, 1812433253ul>;
64
65 void
66 test01()
67 {
68 seed_seq<unsigned> seed;
69 engine_type x(seed);
70 VERIFY( ! seed.called );
71 }
72
73 void
74 test02()
75 {
76 seed_seq<void*> seed;
77 engine_type x(seed);
78 VERIFY( seed.called );
79
80 static_assert(!std::is_constructible<engine_type, const seed_seq<void>&>(),
81 "Cannot construct from a const seed_seq");
82 }
83
84 int main()
85 {
86 test01();
87 test02();
88 }