• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DEBUG >= 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 #include "asan_testing.h"
23 
main()24 int main()
25 {
26     {
27         std::vector<int> v(100);
28         std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
29         assert(v.size() == 105);
30         assert(is_contiguous_container_asan_correct(v));
31         assert(i == v.begin() + 10);
32         int j;
33         for (j = 0; j < 10; ++j)
34             assert(v[j] == 0);
35         for (; j < 15; ++j)
36             assert(v[j] == 1);
37         for (++j; j < 105; ++j)
38             assert(v[j] == 0);
39     }
40     {
41         std::vector<int, stack_allocator<int, 300> > v(100);
42         std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 5, 1);
43         assert(v.size() == 105);
44         assert(is_contiguous_container_asan_correct(v));
45         assert(i == v.begin() + 10);
46         int j;
47         for (j = 0; j < 10; ++j)
48             assert(v[j] == 0);
49         for (; j < 15; ++j)
50             assert(v[j] == 1);
51         for (++j; j < 105; ++j)
52             assert(v[j] == 0);
53     }
54 #if _LIBCPP_DEBUG >= 1
55     {
56         std::vector<int> c1(100);
57         std::vector<int> c2;
58         std::vector<int>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1);
59         assert(false);
60     }
61 #endif
62 #if __cplusplus >= 201103L
63     {
64         std::vector<int, min_allocator<int>> v(100);
65         std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
66         assert(v.size() == 105);
67         assert(is_contiguous_container_asan_correct(v));
68         assert(i == v.begin() + 10);
69         int j;
70         for (j = 0; j < 10; ++j)
71             assert(v[j] == 0);
72         for (; j < 15; ++j)
73             assert(v[j] == 1);
74         for (++j; j < 105; ++j)
75             assert(v[j] == 0);
76     }
77     {
78         std::vector<int, min_allocator<int>> v(100);
79         std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
80         assert(v.size() == 105);
81         assert(is_contiguous_container_asan_correct(v));
82         assert(i == v.begin() + 10);
83         int j;
84         for (j = 0; j < 10; ++j)
85             assert(v[j] == 0);
86         for (; j < 15; ++j)
87             assert(v[j] == 1);
88         for (++j; j < 105; ++j)
89             assert(v[j] == 0);
90     }
91 #if _LIBCPP_DEBUG >= 1
92     {
93         std::vector<int, min_allocator<int>> c1(100);
94         std::vector<int, min_allocator<int>> c2;
95         std::vector<int, min_allocator<int>>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1);
96         assert(false);
97     }
98 #endif
99 #endif
100 }
101