Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.random.shuffle / random_shuffle_rand.pass.cpp
blob5a2b58f4a53542a8610a046bee4dc3faf5f2ee98
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <algorithm>
11 // template<RandomAccessIterator Iter, Callable<auto, Iter::difference_type> Rand>
12 // requires ShuffleIterator<Iter>
13 // && Convertible<Rand::result_type, Iter::difference_type>
14 // void
15 // random_shuffle(Iter first, Iter last, Rand&& rand);
17 // REQUIRES: c++03 || c++11 || c++14
18 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
20 #include <algorithm>
21 #include <cassert>
22 #include <cstddef>
24 #include "test_macros.h"
25 #include "test_iterators.h"
28 struct gen
30 std::ptrdiff_t operator()(std::ptrdiff_t n)
32 return n-1;
37 template <class Iter>
38 void
39 test_with_iterator()
42 int ia[] = {1, 2, 3, 4};
43 int ia1[] = {4, 1, 2, 3};
44 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
45 gen r;
47 std::random_shuffle(ia, ia+sa, r);
48 LIBCPP_ASSERT(std::equal(ia, ia+sa, ia1));
49 assert(std::is_permutation(ia, ia+sa, ia1));
51 std::random_shuffle(ia, ia+sa, r);
52 assert(std::is_permutation(ia, ia+sa, ia1));
56 int main(int, char**)
58 test_with_iterator<random_access_iterator<int*> >();
59 test_with_iterator<int*>();
60 return 0;