]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 26_numerics / random / shuffle_order_engine / cons / seed_seq2.cc
CommitLineData
fbd26352 1// Copyright (C) 2018-2019 Free Software Foundation, Inc.
cae1d5ed 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
24template<typename T>
25struct 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 bool called = false;
55};
56
57using engine_type
58 = std::shuffle_order_engine
59 <
60 std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>,
61 256
62 >;
63
64void
65test01()
66{
67 seed_seq<unsigned> seed;
68 engine_type x(seed);
69 VERIFY( ! seed.called );
70}
71
72void
73test02()
74{
75 seed_seq<void*> seed;
76 engine_type x(seed);
77 VERIFY( seed.called );
78
79 static_assert(!std::is_constructible<engine_type, const seed_seq<void>&>(),
80 "Cannot construct from a const seed_seq");
81}
82
83int main()
84{
85 test01();
86 test02();
87}