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