1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template<RandomAccessIterator Iter, Callable<auto, Iter::difference_type> Rand>
12 // requires ShuffleIterator<Iter>
13 // && Convertible<Rand::result_type, Iter::difference_type>
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
24 #include "test_macros.h"
25 #include "test_iterators.h"
30 std::ptrdiff_t operator()(std::ptrdiff_t n
)
42 int ia
[] = {1, 2, 3, 4};
43 int ia1
[] = {4, 1, 2, 3};
44 const unsigned sa
= sizeof(ia
)/sizeof(ia
[0]);
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
));
58 test_with_iterator
<random_access_iterator
<int*> >();
59 test_with_iterator
<int*>();