]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/algorithm/shuffle.cc
1 // { dg-do run { target c++14 } }
2 // { dg-require-cstdint "" }
3 // { dg-require-effective-target random_device }
4 // { dg-require-effective-target tls_runtime }
5 // { dg-add-options tls }
7 // Derived from: 2010-03-19 Paolo Carlini <paolo.carlini@oracle.com>
9 // Copyright (C) 2010-2023 Free Software Foundation, Inc.
11 // This file is part of the GNU ISO C++ Library. This library is free
12 // software; you can redistribute it and/or modify it under the
13 // terms of the GNU General Public License as published by the
14 // Free Software Foundation; either version 3, or (at your option)
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
22 // You should have received a copy of the GNU General Public License along
23 // with this library; see the file COPYING3. If not see
24 // <http://www.gnu.org/licenses/>.
26 #include <experimental/algorithm>
28 #include <testsuite_hooks.h>
32 for (unsigned size
= 0; size
< 50; ++size
)
34 std::vector
<int> vref(size
);
35 std::iota(vref
.begin(), vref
.end(), 0);
36 std::vector
<int> v1(vref
), v2(vref
);
38 std::experimental::shuffle(v1
.begin(), v1
.end());
39 std::experimental::shuffle(v2
.begin(), v2
.end());
43 VERIFY( !std::equal(v1
.begin(), v1
.end(), vref
.begin()) );
44 VERIFY( !std::equal(v2
.begin(), v2
.end(), vref
.begin()) );
45 VERIFY( !std::equal(v1
.begin(), v1
.end(), v2
.begin()) );
48 for (unsigned ind
= 0; ind
< size
; ++ind
)
50 auto it1
= std::find(v1
.begin(), v1
.end(), vref
[ind
]);
51 auto it2
= std::find(v2
.begin(), v2
.end(), vref
[ind
]);
52 VERIFY( it1
!= v1
.end() );
53 VERIFY( it2
!= v2
.end() );