]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / algorithms / alg.modifying.operations / alg.random.shuffle / random_shuffle_rand.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <algorithm>
11
12 // template<RandomAccessIterator Iter, Callable<auto, Iter::difference_type> Rand>
13 //   requires ShuffleIterator<Iter>
14 //         && Convertible<Rand::result_type, Iter::difference_type>
15 //   void
16 //   random_shuffle(Iter first, Iter last, Rand&& rand);
17
18 #include <algorithm>
19 #include <cassert>
20 #include <cstddef>
21
22 #include "test_macros.h"
23
24 struct gen
25 {
26     std::ptrdiff_t operator()(std::ptrdiff_t n)
27     {
28         return n-1;
29     }
30 };
31
32 int main()
33 {
34     int ia[] = {1, 2, 3, 4};
35     int ia1[] = {4, 1, 2, 3};
36     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
37     gen r;
38     std::random_shuffle(ia, ia+sa, r);
39     LIBCPP_ASSERT(std::equal(ia, ia+sa, ia1));
40     assert(std::is_permutation(ia, ia+sa, ia1));
41 }