1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03 && !stdlib=libc++
10 
11 // <vector>
12 
13 // iterator insert(const_iterator position, value_type&& x);
14 
15 #include <vector>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "MoveOnly.h"
21 #include "min_allocator.h"
22 #include "asan_testing.h"
23 
tests()24 TEST_CONSTEXPR_CXX20 bool tests()
25 {
26     {
27         std::vector<MoveOnly> v(100);
28         std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
29         assert(v.size() == 101);
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] == MoveOnly());
35         assert(v[j] == MoveOnly(3));
36         for (++j; j < 101; ++j)
37             assert(v[j] == MoveOnly());
38     }
39     {
40         std::vector<MoveOnly, limited_allocator<MoveOnly, 300> > v(100);
41         std::vector<MoveOnly, limited_allocator<MoveOnly, 300> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
42         assert(v.size() == 101);
43         assert(is_contiguous_container_asan_correct(v));
44         assert(i == v.begin() + 10);
45         int j;
46         for (j = 0; j < 10; ++j)
47             assert(v[j] == MoveOnly());
48         assert(v[j] == MoveOnly(3));
49         for (++j; j < 101; ++j)
50             assert(v[j] == MoveOnly());
51     }
52     {
53         std::vector<MoveOnly, min_allocator<MoveOnly> > v(100);
54         std::vector<MoveOnly, min_allocator<MoveOnly> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
55         assert(v.size() == 101);
56         assert(is_contiguous_container_asan_correct(v));
57         assert(i == v.begin() + 10);
58         int j;
59         for (j = 0; j < 10; ++j)
60             assert(v[j] == MoveOnly());
61         assert(v[j] == MoveOnly(3));
62         for (++j; j < 101; ++j)
63             assert(v[j] == MoveOnly());
64     }
65 
66     return true;
67 }
68 
main(int,char **)69 int main(int, char**)
70 {
71     tests();
72 #if TEST_STD_VER > 17
73     static_assert(tests());
74 #endif
75     return 0;
76 }
77