]>
Commit | Line | Data |
---|---|---|
8b7af071 FD |
1 | // { dg-do run { target c++11 } } |
2 | // { dg-options "-g -O0" } | |
3 | ||
4 | // | |
83ffe9cd | 5 | // Copyright (C) 2020-2023 Free Software Foundation, Inc. |
8b7af071 FD |
6 | // |
7 | // This file is part of the GNU ISO C++ Library. This library is free | |
8 | // software; you can redistribute it and/or modify it under the | |
9 | // terms of the GNU General Public License as published by the | |
10 | // Free Software Foundation; either version 3, or (at your option) | |
11 | // any later version. | |
12 | // | |
13 | // This library is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | // | |
18 | // You should have received a copy of the GNU General Public License along | |
19 | // with this library; see the file COPYING3. If not see | |
20 | // <http://www.gnu.org/licenses/>. | |
21 | ||
22 | #include <list> | |
23 | #include <memory> | |
24 | #include <testsuite_hooks.h> | |
25 | ||
26 | struct PredLWG526 | |
27 | { | |
28 | PredLWG526(int i) : i_(i) {}; | |
29 | ~PredLWG526() { i_ = -32767; } | |
30 | ||
31 | bool | |
32 | operator() (const PredLWG526& p) const { return p.i_ == i_; } | |
33 | ||
34 | bool | |
35 | operator==(int i) const { return i == i_; } | |
36 | ||
37 | bool | |
38 | operator()(const PredLWG526& lhs, const PredLWG526& rhs) const | |
39 | { | |
40 | VERIFY( i_ != -32767 ); | |
41 | return lhs.i_ == rhs.i_; | |
42 | } | |
43 | ||
44 | friend bool | |
45 | operator==(const PredLWG526& lhs, const PredLWG526& rhs) | |
46 | { return lhs.i_ == rhs.i_; } | |
47 | ||
48 | int i_; | |
49 | }; | |
50 | ||
51 | void test01() | |
52 | { | |
53 | int a1[] = {1, 2, 1, 3, 5, 8, 11}; | |
54 | int a2[] = {2, 3, 5, 8, 11}; | |
55 | std::list<PredLWG526> l(a1, a1 + 7); | |
56 | ||
57 | VERIFY( std::distance(l.begin(), l.end()) == 7 ); | |
58 | ||
59 | l.remove(l.front()); | |
60 | VERIFY( std::distance(l.begin(), l.end()) == 5 ); | |
61 | for (size_t i = 0; !l.empty(); ++i) | |
62 | { | |
63 | VERIFY( l.front() == a2[i] ); | |
64 | l.pop_front(); | |
65 | } | |
66 | } | |
67 | ||
68 | void test02() | |
69 | { | |
70 | int a1[] = {1, 2, 1, 3, 5, 8, 11}; | |
71 | int a2[] = {2, 3, 5, 8, 11}; | |
72 | std::list<PredLWG526> l(a1, a1 + 7); | |
73 | ||
74 | VERIFY( std::distance(l.begin(), l.end()) == 7 ); | |
75 | ||
76 | l.remove_if(std::cref(l.front())); | |
77 | VERIFY( std::distance(l.begin(), l.end()) == 5 ); | |
78 | for (size_t i = 0; !l.empty(); ++i) | |
79 | { | |
80 | VERIFY( l.front() == a2[i] ); | |
81 | l.pop_front(); | |
82 | } | |
83 | } | |
84 | ||
85 | void test03() | |
86 | { | |
87 | int a1[] = {1, 1, 1, 2, 3, 5, 8, 11}; | |
88 | int a2[] = {1, 2, 3, 5, 8, 11}; | |
89 | std::list<PredLWG526> l(a1, a1 + 8); | |
90 | ||
91 | VERIFY( std::distance(l.begin(), l.end()) == 8 ); | |
92 | ||
93 | auto it = l.begin(); | |
94 | ++it; | |
95 | l.unique(std::cref(*it)); | |
96 | VERIFY( std::distance(l.begin(), l.end()) == 6 ); | |
97 | for (size_t i = 0; !l.empty(); ++i) | |
98 | { | |
99 | VERIFY( l.front() == a2[i] ); | |
100 | l.pop_front(); | |
101 | } | |
102 | } | |
103 | ||
104 | int main() | |
105 | { | |
106 | test01(); | |
107 | test02(); | |
108 | test03(); | |
109 | return 0; | |
110 | } |