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 // template <class Iter> 13 // iterator insert(const_iterator position, Iter first, Iter last); 14 15 #if _LIBCPP_DEBUG >= 1 16 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) 17 #endif 18 19 #include <vector> 20 #include <cassert> 21 #include "../../../stack_allocator.h" 22 #include "test_iterators.h" 23 #include "min_allocator.h" 24 25 int main() 26 { 27 { 28 std::vector<int> v(100); 29 int a[] = {1, 2, 3, 4, 5}; 30 const int N = sizeof(a)/sizeof(a[0]); 31 std::vector<int>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a), 32 input_iterator<const int*>(a+N)); 33 assert(v.size() == 100 + N); 34 assert(i == v.begin() + 10); 35 int j; 36 for (j = 0; j < 10; ++j) 37 assert(v[j] == 0); 38 for (int k = 0; k < N; ++j, ++k) 39 assert(v[j] == a[k]); 40 for (; j < 105; ++j) 41 assert(v[j] == 0); 42 } 43 { 44 std::vector<int> v(100); 45 int a[] = {1, 2, 3, 4, 5}; 46 const int N = sizeof(a)/sizeof(a[0]); 47 std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), 48 forward_iterator<const int*>(a+N)); 49 assert(v.size() == 100 + N); 50 assert(i == v.begin() + 10); 51 int j; 52 for (j = 0; j < 10; ++j) 53 assert(v[j] == 0); 54 for (int k = 0; k < N; ++j, ++k) 55 assert(v[j] == a[k]); 56 for (; j < 105; ++j) 57 assert(v[j] == 0); 58 } 59 { 60 std::vector<int, stack_allocator<int, 308> > v(100); 61 int a[] = {1, 2, 3, 4, 5}; 62 const int N = sizeof(a)/sizeof(a[0]); 63 std::vector<int>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a), 64 input_iterator<const int*>(a+N)); 65 assert(v.size() == 100 + N); 66 assert(i == v.begin() + 10); 67 int j; 68 for (j = 0; j < 10; ++j) 69 assert(v[j] == 0); 70 for (int k = 0; k < N; ++j, ++k) 71 assert(v[j] == a[k]); 72 for (; j < 105; ++j) 73 assert(v[j] == 0); 74 } 75 { 76 std::vector<int, stack_allocator<int, 300> > v(100); 77 int a[] = {1, 2, 3, 4, 5}; 78 const int N = sizeof(a)/sizeof(a[0]); 79 std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), 80 forward_iterator<const int*>(a+N)); 81 assert(v.size() == 100 + N); 82 assert(i == v.begin() + 10); 83 int j; 84 for (j = 0; j < 10; ++j) 85 assert(v[j] == 0); 86 for (int k = 0; k < N; ++j, ++k) 87 assert(v[j] == a[k]); 88 for (; j < 105; ++j) 89 assert(v[j] == 0); 90 } 91 #if _LIBCPP_DEBUG >= 1 92 { 93 std::vector<int> v(100); 94 std::vector<int> v2(100); 95 int a[] = {1, 2, 3, 4, 5}; 96 const int N = sizeof(a)/sizeof(a[0]); 97 std::vector<int>::iterator i = v.insert(v2.cbegin() + 10, input_iterator<const int*>(a), 98 input_iterator<const int*>(a+N)); 99 assert(false); 100 } 101 #endif 102 #if __cplusplus >= 201103L 103 { 104 std::vector<int, min_allocator<int>> v(100); 105 int a[] = {1, 2, 3, 4, 5}; 106 const int N = sizeof(a)/sizeof(a[0]); 107 std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a), 108 input_iterator<const int*>(a+N)); 109 assert(v.size() == 100 + N); 110 assert(i == v.begin() + 10); 111 int j; 112 for (j = 0; j < 10; ++j) 113 assert(v[j] == 0); 114 for (int k = 0; k < N; ++j, ++k) 115 assert(v[j] == a[k]); 116 for (; j < 105; ++j) 117 assert(v[j] == 0); 118 } 119 { 120 std::vector<int, min_allocator<int>> v(100); 121 int a[] = {1, 2, 3, 4, 5}; 122 const int N = sizeof(a)/sizeof(a[0]); 123 std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), 124 forward_iterator<const int*>(a+N)); 125 assert(v.size() == 100 + N); 126 assert(i == v.begin() + 10); 127 int j; 128 for (j = 0; j < 10; ++j) 129 assert(v[j] == 0); 130 for (int k = 0; k < N; ++j, ++k) 131 assert(v[j] == a[k]); 132 for (; j < 105; ++j) 133 assert(v[j] == 0); 134 } 135 #if _LIBCPP_DEBUG >= 1 136 { 137 std::vector<int, min_allocator<int>> v(100); 138 std::vector<int, min_allocator<int>> v2(100); 139 int a[] = {1, 2, 3, 4, 5}; 140 const int N = sizeof(a)/sizeof(a[0]); 141 std::vector<int, min_allocator<int>>::iterator i = v.insert(v2.cbegin() + 10, input_iterator<const int*>(a), 142 input_iterator<const int*>(a+N)); 143 assert(false); 144 } 145 #endif 146 #endif 147 } 148