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, 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 "MoveOnly.h"
22 #include "min_allocator.h"
23 #include "asan_testing.h"
24 
main()25 int main()
26 {
27 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
28     {
29         std::vector<MoveOnly> v(100);
30         std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
31         assert(v.size() == 101);
32         assert(is_contiguous_container_asan_correct(v));
33         assert(i == v.begin() + 10);
34         int j;
35         for (j = 0; j < 10; ++j)
36             assert(v[j] == MoveOnly());
37         assert(v[j] == MoveOnly(3));
38         for (++j; j < 101; ++j)
39             assert(v[j] == MoveOnly());
40     }
41     {
42         std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100);
43         std::vector<MoveOnly, stack_allocator<MoveOnly, 300> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
44         assert(v.size() == 101);
45         assert(is_contiguous_container_asan_correct(v));
46         assert(i == v.begin() + 10);
47         int j;
48         for (j = 0; j < 10; ++j)
49             assert(v[j] == MoveOnly());
50         assert(v[j] == MoveOnly(3));
51         for (++j; j < 101; ++j)
52             assert(v[j] == MoveOnly());
53     }
54 #if _LIBCPP_DEBUG >= 1
55     {
56         std::vector<int> v1(3);
57         std::vector<int> v2(3);
58         v1.insert(v2.begin(), 4);
59         assert(false);
60     }
61 #endif
62 #if __cplusplus >= 201103L
63     {
64         std::vector<MoveOnly, min_allocator<MoveOnly>> v(100);
65         std::vector<MoveOnly, min_allocator<MoveOnly>>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
66         assert(v.size() == 101);
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] == MoveOnly());
72         assert(v[j] == MoveOnly(3));
73         for (++j; j < 101; ++j)
74             assert(v[j] == MoveOnly());
75     }
76 #if _LIBCPP_DEBUG >= 1
77     {
78         std::vector<int, min_allocator<int>> v1(3);
79         std::vector<int, min_allocator<int>> v2(3);
80         v1.insert(v2.begin(), 4);
81         assert(false);
82     }
83 #endif
84 #endif
85 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
86 }
87