[lld][WebAssembly] Introduce Ctx::arg
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.modifiers / insert_value.pass.cpp
blob250e19418e45b0793936432f70d871df097d9d8a
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 // iterator insert (const_iterator p, const value_type& v);
13 #include "asan_testing.h"
14 #include <deque>
15 #include <cassert>
16 #include <cstddef>
18 #include "test_macros.h"
19 #include "min_allocator.h"
21 template <class C>
23 make(int size, int start = 0 )
25 const int b = 4096 / sizeof(int);
26 int init = 0;
27 if (start > 0)
29 init = (start+1) / b + ((start+1) % b != 0);
30 init *= b;
31 --init;
33 C c(init, 0);
34 for (int i = 0; i < init-start; ++i)
35 c.pop_back();
36 for (int i = 0; i < size; ++i)
37 c.push_back(i);
38 for (int i = 0; i < start; ++i)
39 c.pop_front();
40 return c;
43 template <class C>
44 void
45 test(int P, C& c1, int x)
47 typedef typename C::const_iterator CI;
48 std::size_t c1_osize = c1.size();
49 CI i = c1.insert(c1.begin() + P, x);
50 assert(i == c1.begin() + P);
51 assert(c1.size() == c1_osize + 1);
52 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
53 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
54 i = c1.begin();
55 for (int j = 0; j < P; ++j, ++i)
56 assert(*i == j);
57 assert(*i == x);
58 ++i;
59 for (int j = P; static_cast<std::size_t>(j) < c1_osize; ++j, ++i)
60 assert(*i == j);
63 template <class C>
64 void
65 testN(int start, int N)
67 for (int i = 0; i <= 3; ++i)
69 if (0 <= i && i <= N)
71 C c1 = make<C>(N, start);
72 test(i, c1, -10);
75 for (int i = N/2-1; i <= N/2+1; ++i)
77 if (0 <= i && i <= N)
79 C c1 = make<C>(N, start);
80 test(i, c1, -10);
83 for (int i = N - 3; i <= N; ++i)
85 if (0 <= i && i <= N)
87 C c1 = make<C>(N, start);
88 test(i, c1, -10);
93 template <class C>
94 void
95 self_reference_test()
97 typedef typename C::const_iterator CI;
98 for (int i = 0; i < 20; ++i)
100 for (int j = 0; j < 20; ++j)
102 C c = make<C>(20);
103 CI it = c.cbegin() + i;
104 CI jt = c.cbegin() + j;
105 c.insert(it, *jt);
106 assert(c.size() == 21);
107 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
108 it = c.cbegin();
109 for (int k = 0; k < i; ++k, ++it)
110 assert(*it == k);
111 assert(*it == j);
112 ++it;
113 for (int k = i; k < 20; ++k, ++it)
114 assert(*it == k);
119 int main(int, char**)
122 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
123 const int N = sizeof(rng)/sizeof(rng[0]);
124 for (int i = 0; i < N; ++i)
125 for (int j = 0; j < N; ++j)
126 testN<std::deque<int> >(rng[i], rng[j]);
127 self_reference_test<std::deque<int> >();
129 #if TEST_STD_VER >= 11
131 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
132 const int N = sizeof(rng)/sizeof(rng[0]);
133 for (int i = 0; i < N; ++i)
134 for (int j = 0; j < N; ++j)
135 testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j]);
136 self_reference_test<std::deque<int, min_allocator<int>> >();
139 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
140 const int N = sizeof(rng)/sizeof(rng[0]);
141 for (int i = 0; i < N; ++i)
142 for (int j = 0; j < N; ++j)
143 testN<std::deque<int, safe_allocator<int>> >(rng[i], rng[j]);
144 self_reference_test<std::deque<int, safe_allocator<int>> >();
146 #endif
148 return 0;