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