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
10 
11 // <vector>
12 
13 // template <class... Args> iterator emplace(const_iterator pos, Args&&... args);
14 
15 #include <vector>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "asan_testing.h"
21 
tests()22 TEST_CONSTEXPR_CXX20 bool tests() {
23     {
24         std::vector<int> v;
25         v.reserve(3);
26         assert(is_contiguous_container_asan_correct(v));
27         v = { 1, 2, 3 };
28         v.emplace(v.begin(), v.back());
29         assert(v[0] == 3);
30         assert(is_contiguous_container_asan_correct(v));
31     }
32     {
33         std::vector<int> v;
34         v.reserve(4);
35         assert(is_contiguous_container_asan_correct(v));
36         v = { 1, 2, 3 };
37         v.emplace(v.begin(), v.back());
38         assert(v[0] == 3);
39         assert(is_contiguous_container_asan_correct(v));
40     }
41     {
42         std::vector<int, min_allocator<int>> v;
43         v.reserve(3);
44         assert(is_contiguous_container_asan_correct(v));
45         v = { 1, 2, 3 };
46         v.emplace(v.begin(), v.back());
47         assert(v[0] == 3);
48         assert(is_contiguous_container_asan_correct(v));
49     }
50     {
51         std::vector<int, min_allocator<int>> v;
52         v.reserve(4);
53         assert(is_contiguous_container_asan_correct(v));
54         v = { 1, 2, 3 };
55         v.emplace(v.begin(), v.back());
56         assert(v[0] == 3);
57         assert(is_contiguous_container_asan_correct(v));
58     }
59     {
60         std::vector<int> v;
61         v.reserve(8);
62         size_t old_capacity = v.capacity();
63         assert(old_capacity >= 8);
64 
65         v.resize(4); // keep the existing capacity
66         assert(v.capacity() == old_capacity);
67 
68         v.emplace(v.cend(), 42);
69         assert(v.size() == 5);
70         assert(v.capacity() == old_capacity);
71         assert(v[4] == 42);
72     }
73 
74     return true;
75 }
76 
main(int,char **)77 int main(int, char**) {
78     tests();
79 #if TEST_STD_VER > 17
80     static_assert(tests());
81 #endif
82     return 0;
83 }
84