[Xtensa] Move XtensaUtils to MCTargetDesc
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.random.shuffle / random_shuffle.pass.cpp
blob90132ba6edf868525fd988ed1cf1a0824fb8bd5e
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>
12 // requires ShuffleIterator<Iter>
13 // void
14 // random_shuffle(Iter first, Iter last);
16 // REQUIRES: c++03 || c++11 || c++14
17 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
19 #include <algorithm>
20 #include <array>
21 #include <cassert>
23 #include "test_macros.h"
24 #include "test_iterators.h"
26 template <class Iter>
27 void
28 test_with_iterator()
30 std::array<int, 0> empty = {};
31 std::random_shuffle(Iter(empty.data()), Iter(empty.data()));
33 const int all_elements[] = {1, 2, 3, 4};
34 int shuffled[] = {1, 2, 3, 4};
35 const unsigned size = sizeof(all_elements) / sizeof(all_elements[0]);
37 std::random_shuffle(Iter(shuffled), Iter(shuffled + size));
38 assert(std::is_permutation(shuffled, shuffled + size, all_elements));
40 std::random_shuffle(Iter(shuffled), Iter(shuffled + size));
41 assert(std::is_permutation(shuffled, shuffled + size, all_elements));
45 int main(int, char**)
47 int ia[] = {1, 2, 3, 4};
48 int ia1[] = {1, 4, 3, 2};
49 int ia2[] = {4, 1, 2, 3};
50 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
52 std::random_shuffle(ia, ia+sa);
53 LIBCPP_ASSERT(std::equal(ia, ia+sa, ia1));
54 assert(std::is_permutation(ia, ia+sa, ia1));
56 std::random_shuffle(ia, ia+sa);
57 LIBCPP_ASSERT(std::equal(ia, ia+sa, ia2));
58 assert(std::is_permutation(ia, ia+sa, ia2));
60 test_with_iterator<random_access_iterator<int*> >();
61 test_with_iterator<int*>();
63 return 0;