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 
     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 int main()
     21 {
     22     int ia[] = {1, 2, 3, 4};
     23     int ia1[] = {1, 4, 3, 2};
     24     int ia2[] = {4, 1, 2, 3};
     25     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     26     std::random_shuffle(ia, ia+sa);
     27     assert(std::equal(ia, ia+sa, ia1));
     28     std::random_shuffle(ia, ia+sa);
     29     assert(std::equal(ia, ia+sa, ia2));
     30 }
     31