[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / list / list.ops / remove.pass.cpp
blob8c9a06273f3e352981791fd49c98e9d2ac84b081
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <list>
11 // void remove(const value_type& value); // pre-c++20
12 // size_type remove(const value_type& value); // c++20 and later
14 #include <list>
15 #include <cassert>
17 #include "test_macros.h"
18 #include "min_allocator.h"
20 struct S {
21 S(int i) : i_(new int(i)) {}
22 S(const S &rhs) : i_(new int(*rhs.i_)) {}
23 S &operator=(const S &rhs) {
24 *i_ = *rhs.i_;
25 return *this;
27 ~S() {
28 delete i_;
29 i_ = NULL;
31 bool operator==(const S &rhs) const { return *i_ == *rhs.i_; }
32 int get() const { return *i_; }
33 int *i_;
36 int main(int, char**) {
38 int a1[] = {1, 2, 3, 4};
39 int a2[] = {1, 2, 4};
40 typedef std::list<int> L;
41 L c(a1, a1 + 4);
42 #if TEST_STD_VER > 17
43 assert(c.remove(3) == 1);
44 ASSERT_SAME_TYPE(L::size_type, decltype(c.remove(3)));
45 #else
46 ASSERT_SAME_TYPE(void, decltype(c.remove(3)));
47 c.remove(3);
48 #endif
50 assert(c == std::list<int>(a2, a2 + 3));
52 { // LWG issue #526
53 int a1[] = {1, 2, 1, 3, 5, 8, 11};
54 int a2[] = {2, 3, 5, 8, 11};
55 std::list<int> c(a1, a1 + 7);
56 c.remove(c.front());
57 assert(c == std::list<int>(a2, a2 + 5));
60 int a1[] = {1, 2, 1, 3, 5, 8, 11, 1};
61 int a2[] = {2, 3, 5, 8, 11};
62 std::list<S> c;
63 for (int *ip = a1; ip < a1 + 8; ++ip)
64 c.push_back(S(*ip));
65 #if TEST_STD_VER > 17
66 assert(c.remove(c.front()) == 3);
67 #else
68 c.remove(c.front());
69 #endif
70 std::list<S>::const_iterator it = c.begin();
71 for (int *ip = a2; ip < a2 + 5; ++ip, ++it) {
72 assert(it != c.end());
73 assert(*ip == it->get());
75 assert(it == c.end());
78 typedef no_default_allocator<int> Alloc;
79 typedef std::list<int, Alloc> List;
80 int a1[] = {1, 2, 3, 4};
81 int a2[] = {1, 2, 4};
82 List c(a1, a1 + 4, Alloc::create());
83 #if TEST_STD_VER > 17
84 assert(c.remove(3) == 1);
85 #else
86 c.remove(3);
87 #endif
88 assert(c == List(a2, a2 + 3, Alloc::create()));
90 #if TEST_STD_VER >= 11
92 int a1[] = {1, 2, 3, 4};
93 int a2[] = {1, 2, 4};
94 std::list<int, min_allocator<int>> c(a1, a1 + 4);
95 #if TEST_STD_VER > 17
96 assert(c.remove(3) == 1);
97 #else
98 c.remove(3);
99 #endif
100 assert((c == std::list<int, min_allocator<int>>(a2, a2 + 3)));
102 #endif
104 return 0;