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 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <list> |
10 | |
11 | // iterator erase(const_iterator first, const_iterator last); |
12 | |
13 | #include <list> |
14 | #include <cassert> |
15 | |
16 | #include "test_macros.h" |
17 | #include "min_allocator.h" |
18 | |
19 | int main(int, char**) |
20 | { |
21 | int a1[] = {1, 2, 3}; |
22 | { |
23 | std::list<int> l1(a1, a1+3); |
24 | std::list<int>::iterator i = l1.erase(first: l1.cbegin(), last: l1.cbegin()); |
25 | assert(l1.size() == 3); |
26 | assert(std::distance(l1.cbegin(), l1.cend()) == 3); |
27 | assert(i == l1.begin()); |
28 | } |
29 | { |
30 | std::list<int> l1(a1, a1+3); |
31 | std::list<int>::iterator i = l1.erase(first: l1.cbegin(), last: std::next(x: l1.cbegin())); |
32 | assert(l1.size() == 2); |
33 | assert(std::distance(l1.cbegin(), l1.cend()) == 2); |
34 | assert(i == l1.begin()); |
35 | assert(l1 == std::list<int>(a1+1, a1+3)); |
36 | } |
37 | { |
38 | std::list<int> l1(a1, a1+3); |
39 | std::list<int>::iterator i = l1.erase(first: l1.cbegin(), last: std::next(x: l1.cbegin(), n: 2)); |
40 | assert(l1.size() == 1); |
41 | assert(std::distance(l1.cbegin(), l1.cend()) == 1); |
42 | assert(i == l1.begin()); |
43 | assert(l1 == std::list<int>(a1+2, a1+3)); |
44 | } |
45 | { |
46 | std::list<int> l1(a1, a1+3); |
47 | std::list<int>::iterator i = l1.erase(first: l1.cbegin(), last: std::next(x: l1.cbegin(), n: 3)); |
48 | assert(l1.size() == 0); |
49 | assert(std::distance(l1.cbegin(), l1.cend()) == 0); |
50 | assert(i == l1.begin()); |
51 | } |
52 | #if TEST_STD_VER >= 11 |
53 | { |
54 | std::list<int, min_allocator<int>> l1(a1, a1+3); |
55 | std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); |
56 | assert(l1.size() == 3); |
57 | assert(std::distance(l1.cbegin(), l1.cend()) == 3); |
58 | assert(i == l1.begin()); |
59 | } |
60 | { |
61 | std::list<int, min_allocator<int>> l1(a1, a1+3); |
62 | std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), std::next(l1.cbegin())); |
63 | assert(l1.size() == 2); |
64 | assert(std::distance(l1.cbegin(), l1.cend()) == 2); |
65 | assert(i == l1.begin()); |
66 | assert((l1 == std::list<int, min_allocator<int>>(a1+1, a1+3))); |
67 | } |
68 | { |
69 | std::list<int, min_allocator<int>> l1(a1, a1+3); |
70 | std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), std::next(l1.cbegin(), 2)); |
71 | assert(l1.size() == 1); |
72 | assert(std::distance(l1.cbegin(), l1.cend()) == 1); |
73 | assert(i == l1.begin()); |
74 | assert((l1 == std::list<int, min_allocator<int>>(a1+2, a1+3))); |
75 | } |
76 | { |
77 | std::list<int, min_allocator<int>> l1(a1, a1+3); |
78 | std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), std::next(l1.cbegin(), 3)); |
79 | assert(l1.size() == 0); |
80 | assert(std::distance(l1.cbegin(), l1.cend()) == 0); |
81 | assert(i == l1.begin()); |
82 | } |
83 | #endif |
84 | |
85 | return 0; |
86 | } |
87 | |