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 
21 struct gen
22 {
operator ()gen23     int operator()(int n)
24     {
25         return n-1;
26     }
27 };
28 
main()29 int main()
30 {
31     int ia[] = {1, 2, 3, 4};
32     int ia1[] = {4, 1, 2, 3};
33     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
34     gen r;
35     std::random_shuffle(ia, ia+sa, r);
36     assert(std::equal(ia, ia+sa, ia1));
37 }
38