[lld][WebAssembly] Introduce Ctx::arg
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.modifiers / emplace.pass.cpp
blobb992610506538a4e08b73a7e7e8788bc157f4607
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 // <deque>
11 // template <class... Args> iterator emplace(const_iterator p, Args&&... args);
13 // UNSUPPORTED: c++03
15 #include "asan_testing.h"
16 #include <deque>
17 #include <cassert>
18 #include <cstddef>
20 #include "test_macros.h"
21 #include "../../../Emplaceable.h"
22 #include "min_allocator.h"
25 template <class C>
27 make(int size, int start = 0 )
29 const int b = 4096 / sizeof(int);
30 int init = 0;
31 if (start > 0)
33 init = (start+1) / b + ((start+1) % b != 0);
34 init *= b;
35 --init;
37 C c(init);
38 for (int i = 0; i < init-start; ++i)
39 c.pop_back();
40 for (int i = 0; i < size; ++i)
41 c.push_back(Emplaceable());
42 for (int i = 0; i < start; ++i)
43 c.pop_front();
44 return c;
47 template <class C>
48 void
49 test(int P, C& c1)
51 typedef typename C::const_iterator CI;
52 std::size_t c1_osize = c1.size();
53 CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5));
54 assert(i == c1.begin() + P);
55 assert(c1.size() == c1_osize + 1);
56 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
57 assert(*i == Emplaceable(1, 2.5));
58 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
61 template <class C>
62 void
63 testN(int start, int N)
65 for (int i = 0; i <= 3; ++i)
67 if (0 <= i && i <= N)
69 C c1 = make<C>(N, start);
70 test(i, c1);
73 for (int i = N/2-1; i <= N/2+1; ++i)
75 if (0 <= i && i <= N)
77 C c1 = make<C>(N, start);
78 test(i, c1);
81 for (int i = N - 3; i <= N; ++i)
83 if (0 <= i && i <= N)
85 C c1 = make<C>(N, start);
86 test(i, c1);
92 int main(int, char**)
95 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
96 const int N = sizeof(rng)/sizeof(rng[0]);
97 for (int i = 0; i < N; ++i)
98 for (int j = 0; j < N; ++j)
99 testN<std::deque<Emplaceable> >(rng[i], rng[j]);
102 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
103 const int N = sizeof(rng)/sizeof(rng[0]);
104 for (int i = 0; i < N; ++i)
105 for (int j = 0; j < N; ++j)
106 testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]);
109 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
110 const int N = sizeof(rng)/sizeof(rng[0]);
111 for (int i = 0; i < N; ++i)
112 for (int j = 0; j < N; ++j)
113 testN<std::deque<Emplaceable, safe_allocator<Emplaceable>> >(rng[i], rng[j]);
116 return 0;