Debian Codegraph @

libstdc++-v3/testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed_seq2.cc

raw
1 // Copyright (C) 2018-2025 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 // { dg-require-little-endian "" }
21
22 #include <ext/random>
23 #include <testsuite_hooks.h>
24
25 template<typename T>
26 struct seed_seq
27 {
28 using result_type = unsigned;
29
30 seed_seq() { }
31
32 template<class U>
33 seed_seq(std::initializer_list<U>) { }
34
35 template<class InputIterator>
36 seed_seq(InputIterator, InputIterator) { }
37
38 template<class RandomAccessIterator>
39 void generate(RandomAccessIterator first, RandomAccessIterator last)
40 {
41 called = true;
42 if (first != last)
43 *first = 42;
44 }
45
46 size_t size() const { called = true; return 1; }
47
48 template<class OutputIterator>
49 void param(OutputIterator dest) const { called = true; dest = 42; }
50
51 // Prevents this type being considered as a seed sequence when
52 // T is convertible to the engine's result_type:
53 operator T() const noexcept { return T(); }
54
55 mutable bool called = false;
56 };
57
58 using engine_type
59 = __gnu_cxx::simd_fast_mersenne_twister_engine<
60 uint32_t, 607, 2,
61 15, 3, 13, 3,
62 0xfdff37ffU, 0xef7f3f7dU,
63 0xff777b7dU, 0x7ff7fb2fU,
64 0x00000001U, 0x00000000U,
65 0x00000000U, 0x5986f054U>;
66
67 void
68 test01()
69 {
70 seed_seq<unsigned> seed;
71 engine_type x(seed);
72 VERIFY( ! seed.called );
73 }
74
75 void
76 test02()
77 {
78 seed_seq<void*> seed;
79 engine_type x(seed);
80 VERIFY( seed.called );
81
82 static_assert(!std::is_constructible<engine_type, const seed_seq<void>&>(),
83 "Cannot construct from a const seed_seq");
84 }
85
86 int main()
87 {
88 test01();
89 test02();
90 }