| 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 |
|
| 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::linear_congruential_engine<unsigned, 48271, 0, 2147483647>; |
| 59 |
|
| 60 |
void |
| 61 |
test01() |
| 62 |
{ |
| 63 |
seed_seq<unsigned> seed; |
| 64 |
engine_type x(seed); |
| 65 |
VERIFY( ! seed.called ); |
| 66 |
} |
| 67 |
|
| 68 |
void |
| 69 |
test02() |
| 70 |
{ |
| 71 |
seed_seq<void*> seed; |
| 72 |
engine_type x(seed); |
| 73 |
VERIFY( seed.called ); |
| 74 |
|
| 75 |
static_assert(!std::is_constructible<engine_type, const seed_seq<void>&>(), |
| 76 |
"Cannot construct from a const seed_seq"); |
| 77 |
} |
| 78 |
|
| 79 |
int main() |
| 80 |
{ |
| 81 |
test01(); |
| 82 |
test02(); |
| 83 |
} |