1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
12 // iterator erase(const_iterator first, const_iterator last);
18 #include "test_macros.h"
19 #include "min_allocator.h"
21 TEST_CONSTEXPR_CXX20
bool tests()
23 bool a1
[] = {1, 0, 1};
25 std::vector
<bool> l1(a1
, a1
+3);
26 std::vector
<bool>::iterator i
= l1
.erase(l1
.cbegin(), l1
.cbegin());
27 assert(l1
.size() == 3);
28 assert(std::distance(l1
.cbegin(), l1
.cend()) == 3);
29 assert(i
== l1
.begin());
32 std::vector
<bool> l1(a1
, a1
+3);
33 std::vector
<bool>::iterator i
= l1
.erase(l1
.cbegin(), std::next(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));
40 std::vector
<bool> l1(a1
, a1
+3);
41 std::vector
<bool>::iterator i
= l1
.erase(l1
.cbegin(), std::next(l1
.cbegin(), 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));
48 std::vector
<bool> l1(a1
, a1
+3);
49 std::vector
<bool>::iterator i
= l1
.erase(l1
.cbegin(), std::next(l1
.cbegin(), 3));
50 assert(l1
.size() == 0);
51 assert(std::distance(l1
.cbegin(), l1
.cend()) == 0);
52 assert(i
== l1
.begin());
54 #if TEST_STD_VER >= 11
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());
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)));
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)));
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());
94 static_assert(tests());