]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/stable_sort/constrained.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / stable_sort / constrained.cc
CommitLineData
7adcbafe 1// Copyright (C) 2020-2022 Free Software Foundation, Inc.
bc464641
PP
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-options "-std=gnu++2a" }
19// { dg-do run { target c++2a } }
20// { dg-require-cstdint "" }
21
22#include <algorithm>
23#include <random>
24#include <vector>
25#include <testsuite_hooks.h>
26#include <testsuite_iterators.h>
27
28using __gnu_test::test_container;
29using __gnu_test::test_range;
30using __gnu_test::random_access_iterator_wrapper;
31
32namespace ranges = std::ranges;
33
34// This test doesn't verify the stability property of ranges::stable_sort,
35// because at the moment it's just defined to be a wrapper over
36// std::stable_sort.
37
38void
39test01()
40{
41 for (unsigned size = 0; size < 50; ++size)
42 {
43 std::vector<int> vref(size);
44 std::iota(vref.begin(), vref.end(), 0);
45 std::vector<int> v1(vref), v2(vref);
46 test_container<int, random_access_iterator_wrapper> c
10a32d47 47 = {v1.data(), v1.data() + size};
bc464641 48 test_range<int, random_access_iterator_wrapper> r
10a32d47 49 = {v2.data(), v2.data() + size};
bc464641
PP
50
51 std::ranlux48_base g1(size), g2(size + 1);
52 ranges::shuffle(c, g1);
53 ranges::shuffle(ranges::begin(r), ranges::end(r), g2);
54
55 auto res1 = ranges::stable_sort(c.begin(), c.end(), {}, std::negate<>{});
56 VERIFY( res1 == c.end() );
57
58 auto res2 = ranges::stable_sort(r, ranges::greater{});
59 VERIFY( res2 == ranges::end(r) );
60
61 VERIFY( ranges::equal(c, r) );
62 VERIFY( ranges::equal(c.begin(), c.end(), vref.rbegin(), vref.rend()) );
63 }
64}
65
66int
67main()
68{
69 test01();
70}