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 TEST_CONSTEXPR_CXX20 bool tests() 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, explicit_allocator<bool>> v(10); 67 std::vector<bool, explicit_allocator<bool>>::iterator i 68 = v.insert(v.cbegin() + 10, 1); 69 assert(v.size() == 11); 70 assert(i == v.begin() + 10); 71 assert(*i == 1); 72 } 73 { 74 std::vector<bool, min_allocator<bool>> v(100); 75 std::vector<bool, min_allocator<bool>>::iterator i = v.insert(v.cbegin() + 10, 1); 76 assert(v.size() == 101); 77 assert(i == v.begin() + 10); 78 std::size_t j; 79 for (j = 0; j < 10; ++j) 80 assert(v[j] == 0); 81 assert(v[j] == 1); 82 for (++j; j < v.size(); ++j) 83 assert(v[j] == 0); 84 } 85 #endif 86 87 return true; 88 } 89 90 int main(int, char**) 91 { 92 tests(); 93 #if TEST_STD_VER > 17 94 static_assert(tests()); 95 #endif 96 return 0; 97 } 98