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