1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <random>
10
11// class seed_seq;
12
13// template<class RandomAccessIterator>
14// void generate(RandomAccessIterator begin, RandomAccessIterator end);
15
16// Check the following requirement: https://eel.is/c++draft/rand.util.seedseq#7
17//
18// Mandates: iterator_traits<RandomAccessIterator>::value_type is an unsigned integer
19// type capable of accommodating 32-bit quantities.
20
21// UNSUPPORTED: c++03
22// REQUIRES: stdlib=libc++
23
24#include <random>
25#include <climits>
26
27#include "test_macros.h"
28
29void f() {
30 std::seed_seq seq;
31
32 // Not an integral type
33 {
34 double* p = nullptr;
35 seq.generate(p, p); // expected-error-re@*:* {{static assertion failed{{.+}}: [rand.util.seedseq]/7 requires{{.+}}}}
36 // expected-error@*:* 0+ {{invalid operands to}}
37 }
38
39 // Not an unsigned type
40 {
41 long long* p = nullptr;
42 seq.generate(p, p); // expected-error-re@*:* {{static assertion failed{{.+}}: [rand.util.seedseq]/7 requires{{.+}}}}
43 }
44
45 // Not a 32-bit type
46 {
47#if UCHAR_MAX < UINT32_MAX
48 unsigned char* p = nullptr;
49 seq.generate(p, p); // expected-error-re@*:* {{static assertion failed{{.+}}: [rand.util.seedseq]/7 requires{{.+}}}}
50#endif
51 }
52
53 // Everything satisfied
54 {
55 unsigned long* p = nullptr;
56 seq.generate(p, p); // no diagnostic
57 }
58}
59

source code of libcxx/test/std/numerics/rand/rand.util/rand.util.seedseq/generate.mandates.verify.cpp