• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
13 //   requires ShuffleIterator<Iter>
14 //   void
15 //   random_shuffle(Iter first, Iter last);
16 
17 #include <algorithm>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 
main()22 int main()
23 {
24     int ia[] = {1, 2, 3, 4};
25     int ia1[] = {1, 4, 3, 2};
26     int ia2[] = {4, 1, 2, 3};
27     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
28     std::random_shuffle(ia, ia+sa);
29     LIBCPP_ASSERT(std::equal(ia, ia+sa, ia1));
30     assert(std::is_permutation(ia, ia+sa, ia1));
31     std::random_shuffle(ia, ia+sa);
32     LIBCPP_ASSERT(std::equal(ia, ia+sa, ia2));
33     assert(std::is_permutation(ia, ia+sa, ia2));
34 }
35