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 18 #include "min_allocator.h" 19 main()20int main() 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 int 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 int 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 int 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 __cplusplus >= 201103L 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 int 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