]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/sort_heap/check_compare_by_value.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / sort_heap / check_compare_by_value.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
60c5236e 2
8d9254fc 3// Copyright (C) 2011-2020 Free Software Foundation, Inc.
60c5236e
PC
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20#undef _GLIBCXX_CONCEPT_CHECKS
21
60c5236e
PC
22#include <algorithm>
23#include <testsuite_hooks.h>
24#include <testsuite_iterators.h>
25#include <testsuite_rvalref.h>
26
27using __gnu_test::test_container;
28using __gnu_test::random_access_iterator_wrapper;
29
30typedef __gnu_test::rvalstruct_compare_by_value V;
31typedef test_container<V, random_access_iterator_wrapper> Container;
32
33void
34test01()
35{
60c5236e
PC
36 V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
37 17, 8, 18, 9, 19 };
38 const int N = sizeof(s1) / sizeof(V);
39 Container con(s1, s1 + N);
40 std::make_heap(con.begin(), con.end());
41 std::sort_heap(con.begin(), con.end());
42 VERIFY( s1[0].ok );
43 for(int i = 1; i < N; ++i)
44 VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok );
45}
46
47void
48test02()
49{
60c5236e
PC
50 V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
51 17, 8, 18, 9, 19 };
52 const int N = sizeof(s1) / sizeof(V);
53 Container con(s1, s1 + N);
54 std::make_heap(con.begin(), con.end(), __gnu_test::order);
55 std::sort_heap(con.begin(), con.end(), __gnu_test::order);
56 VERIFY( s1[0].ok );
57 for(int i = 1; i < N; ++i)
58 VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok );
59}
60
61void
62test03()
63{
60c5236e
PC
64 V vvs[] = { 2, 0 };
65 std::make_heap(vvs, vvs + 2);
66 std::sort_heap(vvs, vvs + 2);
67 VERIFY( vvs[0].ok && vvs[0].val == 0 );
68 VERIFY( vvs[1].ok && vvs[1].val == 2 );
69}
70
71int
72main()
73{
74 test01();
75 test02();
76 test03();
77 return 0;
78}