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

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