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 position);
13
14#include <vector>
15#include <cassert>
16#include <iterator>
17
18#include "test_macros.h"
19#include "min_allocator.h"
20
21TEST_CONSTEXPR_CXX20 bool tests()
22{
23 bool a1[] = {1, 0, 1};
24 {
25 std::vector<bool> l1(a1, a1+3);
26 std::vector<bool>::const_iterator i = l1.begin();
27 ++i;
28 std::vector<bool>::iterator j = l1.erase(position: i);
29 assert(l1.size() == 2);
30 assert(std::distance(l1.begin(), l1.end()) == 2);
31 assert(*j == true);
32 assert(*l1.begin() == 1);
33 assert(*std::next(l1.begin()) == true);
34 j = l1.erase(position: j);
35 assert(j == l1.end());
36 assert(l1.size() == 1);
37 assert(std::distance(l1.begin(), l1.end()) == 1);
38 assert(*l1.begin() == true);
39 j = l1.erase(position: l1.begin());
40 assert(j == l1.end());
41 assert(l1.size() == 0);
42 assert(std::distance(l1.begin(), l1.end()) == 0);
43 }
44#if TEST_STD_VER >= 11
45 {
46 std::vector<bool, min_allocator<bool>> l1(a1, a1+3);
47 std::vector<bool, min_allocator<bool>>::const_iterator i = l1.begin();
48 ++i;
49 std::vector<bool, min_allocator<bool>>::iterator j = l1.erase(i);
50 assert(l1.size() == 2);
51 assert(std::distance(l1.begin(), l1.end()) == 2);
52 assert(*j == true);
53 assert(*l1.begin() == 1);
54 assert(*std::next(l1.begin()) == true);
55 j = l1.erase(j);
56 assert(j == l1.end());
57 assert(l1.size() == 1);
58 assert(std::distance(l1.begin(), l1.end()) == 1);
59 assert(*l1.begin() == true);
60 j = l1.erase(l1.begin());
61 assert(j == l1.end());
62 assert(l1.size() == 0);
63 assert(std::distance(l1.begin(), l1.end()) == 0);
64 }
65#endif
66
67 return true;
68}
69
70int main(int, char**)
71{
72 tests();
73#if TEST_STD_VER > 17
74 static_assert(tests());
75#endif
76 return 0;
77}
78

source code of libcxx/test/std/containers/sequences/vector.bool/erase_iter.pass.cpp