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