1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <vector> 11 // vector<bool> 12 13 // iterator insert(const_iterator position, const value_type& x); 14 15 #include <vector> 16 #include <cassert> 17 #include <cstddef> 18 19 #include "min_allocator.h" 20 21 int main() 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