]>
Commit | Line | Data |
---|---|---|
3a63c9cd ESR |
1 | // { dg-options "-std=gnu++0x" } |
2 | ||
aa118a03 | 3 | // Copyright (C) 2008-2014 Free Software Foundation, Inc. |
3a63c9cd ESR |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
3a63c9cd ESR |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
2328b1de | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
3a63c9cd ESR |
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 | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
3a63c9cd ESR |
19 | |
20 | // 23.2.3.n forward_list xxx [lib.forward_list.xxx] | |
21 | ||
22 | #include <forward_list> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | bool test __attribute__((unused)) = true; | |
26 | ||
27 | // Comparison functor. | |
28 | template<typename Num> | |
29 | class Comp | |
30 | { | |
31 | public: | |
32 | Comp(const Num & num) | |
33 | { | |
34 | n = num; | |
35 | } | |
36 | bool operator()(const Num i, const Num j) | |
37 | { | |
38 | return (n * i) < (n * j); | |
39 | } | |
40 | private: | |
41 | Num n; | |
42 | }; | |
43 | ||
44 | // This test verifies the following: | |
45 | // | |
46 | void | |
47 | test01() | |
48 | { | |
49 | const unsigned int n = 13; | |
50 | int order[][n] = { | |
51 | { 0,1,2,3,4,5,6,7,8,9,10,11,12 }, | |
52 | { 6,2,8,4,11,1,12,7,3,9,5,0,10 }, | |
53 | { 12,11,10,9,8,7,6,5,4,3,2,1,0 }, | |
54 | }; | |
55 | std::forward_list<int> sorted(order[0], order[0] + n); | |
56 | ||
57 | for (unsigned int i = 0; i < sizeof(order)/sizeof(*order); ++i) | |
58 | { | |
59 | std::forward_list<int> head(order[i], order[i] + n); | |
60 | ||
61 | head.sort(); | |
62 | ||
63 | VERIFY(head == sorted); | |
64 | } | |
65 | ||
66 | std::forward_list<int> reversed(order[2], order[2] + n); | |
67 | for (unsigned int i = 0; i < sizeof(order)/sizeof(*order); ++i) | |
68 | { | |
69 | std::forward_list<int> head(order[i], order[i] + n); | |
70 | ||
71 | Comp<int> comp(-1); | |
72 | head.sort( comp ); | |
73 | ||
74 | VERIFY(head == reversed); | |
75 | } | |
76 | } | |
77 | ||
78 | int | |
79 | main() | |
80 | { | |
81 | test01(); | |
82 | return 0; | |
83 | } |