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 12 // iterator insert(const_iterator position, size_type n, const value_type& x); 13 14 #if _LIBCPP_DEBUG2 >= 1 15 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) 16 #endif 17 18 #include <vector> 19 #include <cassert> 20 #include "../../../stack_allocator.h" 21 #include "../../../min_allocator.h" 22 23 int main() 24 { 25 { 26 std::vector<int> v(100); 27 std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1); 28 assert(v.size() == 105); 29 assert(i == v.begin() + 10); 30 int j; 31 for (j = 0; j < 10; ++j) 32 assert(v[j] == 0); 33 for (; j < 15; ++j) 34 assert(v[j] == 1); 35 for (++j; j < 105; ++j) 36 assert(v[j] == 0); 37 } 38 { 39 std::vector<int, stack_allocator<int, 300> > v(100); 40 std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 5, 1); 41 assert(v.size() == 105); 42 assert(i == v.begin() + 10); 43 int j; 44 for (j = 0; j < 10; ++j) 45 assert(v[j] == 0); 46 for (; j < 15; ++j) 47 assert(v[j] == 1); 48 for (++j; j < 105; ++j) 49 assert(v[j] == 0); 50 } 51 #if _LIBCPP_DEBUG2 >= 1 52 { 53 std::vector<int> c1(100); 54 std::vector<int> c2; 55 std::vector<int>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1); 56 assert(false); 57 } 58 #endif 59 #if __cplusplus >= 201103L 60 { 61 std::vector<int, min_allocator<int>> v(100); 62 std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1); 63 assert(v.size() == 105); 64 assert(i == v.begin() + 10); 65 int j; 66 for (j = 0; j < 10; ++j) 67 assert(v[j] == 0); 68 for (; j < 15; ++j) 69 assert(v[j] == 1); 70 for (++j; j < 105; ++j) 71 assert(v[j] == 0); 72 } 73 { 74 std::vector<int, min_allocator<int>> v(100); 75 std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1); 76 assert(v.size() == 105); 77 assert(i == v.begin() + 10); 78 int j; 79 for (j = 0; j < 10; ++j) 80 assert(v[j] == 0); 81 for (; j < 15; ++j) 82 assert(v[j] == 1); 83 for (++j; j < 105; ++j) 84 assert(v[j] == 0); 85 } 86 #if _LIBCPP_DEBUG2 >= 1 87 { 88 std::vector<int, min_allocator<int>> c1(100); 89 std::vector<int, min_allocator<int>> c2; 90 std::vector<int, min_allocator<int>>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1); 91 assert(false); 92 } 93 #endif 94 #endif 95 } 96