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 position); |
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 | { |
22 | int a1[] = {1, 2, 3}; |
23 | std::list<int> l1(a1, a1+3); |
24 | std::list<int>::const_iterator i = l1.begin(); |
25 | ++i; |
26 | std::list<int>::iterator j = l1.erase(position: i); |
27 | assert(l1.size() == 2); |
28 | assert(std::distance(l1.begin(), l1.end()) == 2); |
29 | assert(*j == 3); |
30 | assert(*l1.begin() == 1); |
31 | assert(*std::next(l1.begin()) == 3); |
32 | j = l1.erase(position: j); |
33 | assert(j == l1.end()); |
34 | assert(l1.size() == 1); |
35 | assert(std::distance(l1.begin(), l1.end()) == 1); |
36 | assert(*l1.begin() == 1); |
37 | j = l1.erase(position: l1.begin()); |
38 | assert(j == l1.end()); |
39 | assert(l1.size() == 0); |
40 | assert(std::distance(l1.begin(), l1.end()) == 0); |
41 | } |
42 | #if TEST_STD_VER >= 11 |
43 | { |
44 | int a1[] = {1, 2, 3}; |
45 | std::list<int, min_allocator<int>> l1(a1, a1+3); |
46 | std::list<int, min_allocator<int>>::const_iterator i = l1.begin(); |
47 | ++i; |
48 | std::list<int, min_allocator<int>>::iterator j = l1.erase(i); |
49 | assert(l1.size() == 2); |
50 | assert(std::distance(l1.begin(), l1.end()) == 2); |
51 | assert(*j == 3); |
52 | assert(*l1.begin() == 1); |
53 | assert(*std::next(l1.begin()) == 3); |
54 | j = l1.erase(j); |
55 | assert(j == l1.end()); |
56 | assert(l1.size() == 1); |
57 | assert(std::distance(l1.begin(), l1.end()) == 1); |
58 | assert(*l1.begin() == 1); |
59 | j = l1.erase(l1.begin()); |
60 | assert(j == l1.end()); |
61 | assert(l1.size() == 0); |
62 | assert(std::distance(l1.begin(), l1.end()) == 0); |
63 | } |
64 | #endif |
65 | |
66 | return 0; |
67 | } |
68 | |