76 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <random>10 11// class seed_seq;12 13// template<class InputIterator>14// seed_seq(InputIterator begin, InputIterator end);15 16#include <random>17#include <cassert>18 19#include "test_macros.h"20 21void test()22{23 {24 unsigned a[5] = {5, 4, 3, 2, 1};25 std::seed_seq s(a, a+5);26 assert(s.size() == 5);27 28 unsigned b[5] = {0};29 s.param(b);30 assert(b[0] == 5);31 assert(b[1] == 4);32 assert(b[2] == 3);33 assert(b[3] == 2);34 assert(b[4] == 1);35 }36 {37 // Test truncation to 32 bits38 unsigned long long a[4] = {39 0x1234000056780000uLL,40 0x0000001234567800uLL,41 0xFFFFFFFFFFFFFFFFuLL,42 0x0000000180000000uLL,43 };44 std::seed_seq s(a, a+4);45 assert(s.size() == 4);46 47 unsigned b[4] = {0};48 s.param(b);49 assert(b[0] == 0x56780000u);50 assert(b[1] == 0x34567800u);51 assert(b[2] == 0xFFFFFFFFu);52 assert(b[3] == 0x80000000u);53 }54#if TEST_STD_VER >= 1155 {56 // Test uniform initialization syntax (LWG 3422)57 unsigned a[3] = {1, 2, 3};58 std::seed_seq s{a, a+3}; // uniform initialization59 assert(s.size() == 3);60 61 unsigned b[3] = {0};62 s.param(b);63 assert(b[0] == 1);64 assert(b[1] == 2);65 assert(b[2] == 3);66 }67#endif // TEST_STD_VER >= 1168}69 70int main(int, char**)71{72 test();73 74 return 0;75}76