random_shuffle_rand.pass.cpp 946 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <algorithm>
  10. // template<RandomAccessIterator Iter, Callable<auto, Iter::difference_type> Rand>
  11. // requires ShuffleIterator<Iter>
  12. // && Convertible<Rand::result_type, Iter::difference_type>
  13. // void
  14. // random_shuffle(Iter first, Iter last, Rand&& rand);
  15. #include <algorithm>
  16. #include <cassert>
  17. struct gen
  18. {
  19. int operator()(int n)
  20. {
  21. return n-1;
  22. }
  23. };
  24. int main()
  25. {
  26. int ia[] = {1, 2, 3, 4};
  27. int ia1[] = {4, 1, 2, 3};
  28. const unsigned sa = sizeof(ia)/sizeof(ia[0]);
  29. gen r;
  30. std::random_shuffle(ia, ia+sa, r);
  31. assert(std::equal(ia, ia+sa, ia1));
  32. }