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