[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / sequences / vector / vector.modifiers / emplace_extra.pass.cpp
blobf186a0d97ae39b7b24012692b518736e65ac2a2e
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <vector>
13 // template <class... Args> iterator emplace(const_iterator pos, Args&&... args);
15 #include <vector>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "asan_testing.h"
22 TEST_CONSTEXPR_CXX20 bool tests() {
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));
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));
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));
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));
60 std::vector<int, safe_allocator<int>> v;
61 v.reserve(3);
62 assert(is_contiguous_container_asan_correct(v));
63 v = {1, 2, 3};
64 v.emplace(v.begin(), v.back());
65 assert(v[0] == 3);
66 assert(is_contiguous_container_asan_correct(v));
69 std::vector<int, safe_allocator<int>> v;
70 v.reserve(4);
71 assert(is_contiguous_container_asan_correct(v));
72 v = {1, 2, 3};
73 v.emplace(v.begin(), v.back());
74 assert(v[0] == 3);
75 assert(is_contiguous_container_asan_correct(v));
78 std::vector<int> v;
79 v.reserve(8);
80 std::size_t old_capacity = v.capacity();
81 assert(old_capacity >= 8);
83 v.resize(4); // keep the existing capacity
84 assert(v.capacity() == old_capacity);
86 v.emplace(v.cend(), 42);
87 assert(v.size() == 5);
88 assert(v.capacity() == old_capacity);
89 assert(v[4] == 42);
92 return true;
95 int main(int, char**) {
96 tests();
97 #if TEST_STD_VER > 17
98 static_assert(tests());
99 #endif
100 return 0;