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