Home | History | Annotate | Download | only in alg.random.shuffle
      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 // REQUIRES: c++98 || c++03 || c++11 || c++14
     12 
     13 // template<RandomAccessIterator Iter>
     14 //   requires ShuffleIterator<Iter>
     15 //   void
     16 //   random_shuffle(Iter first, Iter last);
     17 
     18 #include <algorithm>
     19 #include <cassert>
     20 
     21 #include "test_macros.h"
     22 
     23 int main()
     24 {
     25     int ia[] = {1, 2, 3, 4};
     26     int ia1[] = {1, 4, 3, 2};
     27     int ia2[] = {4, 1, 2, 3};
     28     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     29     std::random_shuffle(ia, ia+sa);
     30     LIBCPP_ASSERT(std::equal(ia, ia+sa, ia1));
     31     assert(std::is_permutation(ia, ia+sa, ia1));
     32     std::random_shuffle(ia, ia+sa);
     33     LIBCPP_ASSERT(std::equal(ia, ia+sa, ia2));
     34     assert(std::is_permutation(ia, ia+sa, ia2));
     35 }
     36