xref: /llvm-project/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp (revision e3dd9f7e66fec22986605da2dcd8120a7864455d)
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       std::vector<MoveOnly, safe_allocator<MoveOnly> > v(100);
67       std::vector<MoveOnly, safe_allocator<MoveOnly> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
68       assert(v.size() == 101);
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] == MoveOnly());
74       assert(v[j] == MoveOnly(3));
75       for (++j; j < 101; ++j)
76         assert(v[j] == MoveOnly());
77     }
78 
79     return true;
80 }
81 
main(int,char **)82 int main(int, char**)
83 {
84     tests();
85 #if TEST_STD_VER > 17
86     static_assert(tests());
87 #endif
88     return 0;
89 }
90