]>
Commit | Line | Data |
---|---|---|
1 | // { dg-do run { target c++11 } } | |
2 | ||
3 | // Copyright (C) 2011-2020 Free Software Foundation, Inc. | |
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 | ||
22 | #include <algorithm> | |
23 | #include <testsuite_hooks.h> | |
24 | #include <testsuite_iterators.h> | |
25 | #include <testsuite_rvalref.h> | |
26 | ||
27 | using __gnu_test::test_container; | |
28 | using __gnu_test::random_access_iterator_wrapper; | |
29 | ||
30 | typedef __gnu_test::rvalstruct_compare_by_value V; | |
31 | typedef test_container<V, random_access_iterator_wrapper> Container; | |
32 | ||
33 | void | |
34 | test01() | |
35 | { | |
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 | ||
47 | void | |
48 | test02() | |
49 | { | |
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 | ||
61 | void | |
62 | test03() | |
63 | { | |
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 | ||
71 | int | |
72 | main() | |
73 | { | |
74 | test01(); | |
75 | test02(); | |
76 | test03(); | |
77 | return 0; | |
78 | } |