]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
60c5236e | 2 | |
a945c346 | 3 | // Copyright (C) 2011-2024 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 | // 25.3.1.3 [lib.partial.sort] | |
21 | ||
22 | #undef _GLIBCXX_CONCEPT_CHECKS | |
23 | ||
24 | // XXX FIXME: parallel-mode should deal correctly with moveable-only types | |
25 | // per C++0x, at minimum smoothly fall back to serial. | |
26 | #undef _GLIBCXX_PARALLEL | |
27 | ||
28 | #include <algorithm> | |
29 | #include <testsuite_hooks.h> | |
30 | #include <testsuite_iterators.h> | |
31 | #include <testsuite_rvalref.h> | |
32 | ||
33 | using __gnu_test::test_container; | |
34 | using __gnu_test::random_access_iterator_wrapper; | |
35 | ||
36 | typedef __gnu_test::rvalstruct_compare_by_value V; | |
37 | typedef test_container<V, random_access_iterator_wrapper> Container; | |
38 | ||
39 | void | |
40 | test01() | |
41 | { | |
60c5236e PC |
42 | V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, |
43 | 17, 8, 18, 9, 19 }; | |
44 | const int N = sizeof(s1) / sizeof(V); | |
45 | Container con(s1, s1 + N); | |
46 | std::partial_sort(con.begin(), con.begin() + 10, con.end()); | |
47 | VERIFY( s1[0].ok ); | |
48 | for(int i = 1; i < 10; ++i) | |
49 | VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok ); | |
50 | for(int i = 10; i < N; ++i) | |
51 | VERIFY( s1[i].val > s1[9].val && s1[i].ok ); | |
52 | ||
53 | } | |
54 | ||
55 | void | |
56 | test02() | |
57 | { | |
60c5236e PC |
58 | V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, |
59 | 17, 8, 18, 9, 19 }; | |
60 | const int N = sizeof(s1) / sizeof(V); | |
61 | Container con(s1, s1 + N); | |
62 | std::partial_sort(con.begin(), con.begin() + 10, con.end(), | |
63 | __gnu_test::order); | |
64 | VERIFY( s1[0].ok ); | |
65 | for(int i = 1; i < 10; ++i) | |
66 | VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok ); | |
67 | for(int i = 10; i < N; ++i) | |
68 | VERIFY( s1[i].val > s1[9].val && s1[i].ok ); | |
69 | } | |
70 | ||
71 | void | |
72 | test03() | |
73 | { | |
60c5236e PC |
74 | V vvs[] = { 2, 0 }; |
75 | std::partial_sort(vvs, vvs + 2, vvs + 2); | |
76 | VERIFY( vvs[0].ok && vvs[0].val == 0 ); | |
77 | VERIFY( vvs[1].ok && vvs[1].val == 2 ); | |
78 | } | |
79 | ||
80 | int | |
81 | main() | |
82 | { | |
83 | test01(); | |
84 | test02(); | |
85 | test03(); | |
86 | return 0; | |
87 | } |