]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc
libstdc++: Deprecate std::random_shuffle for C++14
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / random_shuffle / moveable.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
7f2f4b87 2// { dg-add-options using-deprecated }
01bbe151 3
99dee823 4// Copyright (C) 2009-2021 Free Software Foundation, Inc.
01bbe151
CJ
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 3, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
20
21// 25.2.11 random_shuffle()
22
932f6f4a
PC
23// XXX FIXME: parallel-mode should deal correctly with moveable-only types
24// per C++0x, at minimum smoothly fall back to serial.
25#undef _GLIBCXX_PARALLEL
26
01bbe151
CJ
27#include <algorithm>
28#include <testsuite_hooks.h>
29#include <testsuite_iterators.h>
30#include <testsuite_rvalref.h>
31
32using __gnu_test::test_container;
33using __gnu_test::random_access_iterator_wrapper;
34using __gnu_test::rvalstruct;
35
36typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
37
6b6254db
AR
38const unsigned int N = 10000;
39int A[N]; // This is made global because we don't want it on the stack
01bbe151
CJ
40
41void fill_ascending()
42{
43 for (int i = 0; i < N; ++i)
44 A[i] = i;
45}
46
47void
48test01()
49{
01bbe151
CJ
50 fill_ascending();
51 rvalstruct rv[N];
52 std::copy(A, A + N, rv);
53 Container con(rv, rv + N);
54 std::random_shuffle(con.begin(), con.end());
55
56 // The chance that random_shuffle leaves the order as is by coincidence
57 // is negligible, so we expect it to be permuted
58 VERIFY( !std::equal(rv, rv + N, A) );
59
60 std::sort(con.begin(), con.end());
61 VERIFY( std::equal(rv, rv + N, A) );
62}
63
64int random_generator(int)
65{ return 0; }
66
67void
68test02()
69{
01bbe151
CJ
70 rvalstruct rv[10] = {1,2,3,4,5,6,7,8,9,10};
71 int result[10] = {10,1,2,3,4,5,6,7,8,9};
72 Container con(rv, rv + 10);
73 std::random_shuffle(con.begin(), con.end(), random_generator);
74 // The above answer was generated by hand. It is not required by the standard,
75 // but is produced by the current algorithm.
76 VERIFY( std::equal(rv, rv + 10, result) );
77}
78
79int
80main()
81{
82 test01();
83 test02();
84 return 0;
85}