[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.modifiers / insert_iter_iter.pass.cpp
blob9a5f05476d393e8fc0e4d06a188419b32c50c553
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 // REQUIRES: long_tests
11 // <deque>
13 // template <class InputIterator>
14 // iterator insert (const_iterator p, InputIterator f, InputIterator l);
16 #include <deque>
17 #include <cassert>
18 #include <cstddef>
20 #include "test_macros.h"
21 #include "test_iterators.h"
22 #include "MoveOnly.h"
23 #include "test_allocator.h"
24 #include "min_allocator.h"
26 template <class C>
28 make(int size, int start = 0 )
30 const int b = 4096 / sizeof(int);
31 int init = 0;
32 if (start > 0)
34 init = (start+1) / b + ((start+1) % b != 0);
35 init *= b;
36 --init;
38 C c(init, 0);
39 for (int i = 0; i < init-start; ++i)
40 c.pop_back();
41 for (int i = 0; i < size; ++i)
42 c.push_back(i);
43 for (int i = 0; i < start; ++i)
44 c.pop_front();
45 return c;
48 template <class C>
49 void
50 test(int P, const C& c0, const C& c2)
53 typedef typename C::const_iterator CI;
54 typedef input_iterator<CI> BCI;
55 C c1 = c0;
56 std::size_t c1_osize = c1.size();
57 CI i = c1.insert(c1.begin() + P, BCI(c2.begin()), BCI(c2.end()));
58 assert(i == c1.begin() + P);
59 assert(c1.size() == c1_osize + c2.size());
60 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
61 i = c1.begin();
62 for (int j = 0; j < P; ++j, ++i)
63 assert(*i == j);
64 for (int j = 0; static_cast<std::size_t>(j) < c2.size(); ++j, ++i)
65 assert(*i == j);
66 for (int j = P; static_cast<std::size_t>(j) < c1_osize; ++j, ++i)
67 assert(*i == j);
70 typedef typename C::const_iterator CI;
71 typedef forward_iterator<CI> BCI;
72 C c1 = c0;
73 std::size_t c1_osize = c1.size();
74 CI i = c1.insert(c1.begin() + P, BCI(c2.begin()), BCI(c2.end()));
75 assert(i == c1.begin() + P);
76 assert(c1.size() == c1_osize + c2.size());
77 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
78 i = c1.begin();
79 for (int j = 0; j < P; ++j, ++i)
80 assert(*i == j);
81 for (int j = 0; static_cast<std::size_t>(j) < c2.size(); ++j, ++i)
82 assert(*i == j);
83 for (int j = P; static_cast<std::size_t>(j) < c1_osize; ++j, ++i)
84 assert(*i == j);
87 typedef typename C::const_iterator CI;
88 typedef bidirectional_iterator<CI> BCI;
89 C c1 = c0;
90 std::size_t c1_osize = c1.size();
91 CI i = c1.insert(c1.begin() + P, BCI(c2.begin()), BCI(c2.end()));
92 assert(i == c1.begin() + P);
93 assert(c1.size() == c1_osize + c2.size());
94 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
95 i = c1.begin();
96 for (int j = 0; j < P; ++j, ++i)
97 assert(*i == j);
98 for (int j = 0; static_cast<std::size_t>(j) < c2.size(); ++j, ++i)
99 assert(*i == j);
100 for (int j = P; static_cast<std::size_t>(j) < c1_osize; ++j, ++i)
101 assert(*i == j);
105 template <class C>
106 void
107 testN(int start, int N, int M)
109 for (int i = 0; i <= 3; ++i)
111 if (0 <= i && i <= N)
113 C c1 = make<C>(N, start);
114 C c2 = make<C>(M);
115 test(i, c1, c2);
118 for (int i = M-1; i <= M+1; ++i)
120 if (0 <= i && i <= N)
122 C c1 = make<C>(N, start);
123 C c2 = make<C>(M);
124 test(i, c1, c2);
127 for (int i = N/2-1; i <= N/2+1; ++i)
129 if (0 <= i && i <= N)
131 C c1 = make<C>(N, start);
132 C c2 = make<C>(M);
133 test(i, c1, c2);
136 for (int i = N - M - 1; i <= N - M + 1; ++i)
138 if (0 <= i && i <= N)
140 C c1 = make<C>(N, start);
141 C c2 = make<C>(M);
142 test(i, c1, c2);
145 for (int i = N - M - 1; i <= N - M + 1; ++i)
147 if (0 <= i && i <= N)
149 C c1 = make<C>(N, start);
150 C c2 = make<C>(M);
151 test(i, c1, c2);
154 for (int i = N - 3; i <= N; ++i)
156 if (0 <= i && i <= N)
158 C c1 = make<C>(N, start);
159 C c2 = make<C>(M);
160 test(i, c1, c2);
165 template <class C>
166 void
167 testI(int P, C& c1, const C& c2)
169 typedef typename C::const_iterator CI;
170 typedef input_iterator<CI> ICI;
171 std::size_t c1_osize = c1.size();
172 CI i = c1.insert(c1.begin() + P, ICI(c2.begin()), ICI(c2.end()));
173 assert(i == c1.begin() + P);
174 assert(c1.size() == c1_osize + c2.size());
175 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
176 i = c1.begin();
177 for (int j = 0; j < P; ++j, ++i)
178 assert(*i == j);
179 for (int j = 0; static_cast<std::size_t>(j) < c2.size(); ++j, ++i)
180 assert(*i == j);
181 for (int j = P; static_cast<std::size_t>(j) < c1_osize; ++j, ++i)
182 assert(*i == j);
185 template <class C>
186 void
187 testNI(int start, int N, int M)
189 for (int i = 0; i <= 3; ++i)
191 if (0 <= i && i <= N)
193 C c1 = make<C>(N, start);
194 C c2 = make<C>(M);
195 testI(i, c1, c2);
198 for (int i = M-1; i <= M+1; ++i)
200 if (0 <= i && i <= N)
202 C c1 = make<C>(N, start);
203 C c2 = make<C>(M);
204 testI(i, c1, c2);
207 for (int i = N/2-1; i <= N/2+1; ++i)
209 if (0 <= i && i <= N)
211 C c1 = make<C>(N, start);
212 C c2 = make<C>(M);
213 testI(i, c1, c2);
216 for (int i = N - M - 1; i <= N - M + 1; ++i)
218 if (0 <= i && i <= N)
220 C c1 = make<C>(N, start);
221 C c2 = make<C>(M);
222 testI(i, c1, c2);
225 for (int i = N - 3; i <= N; ++i)
227 if (0 <= i && i <= N)
229 C c1 = make<C>(N, start);
230 C c2 = make<C>(M);
231 testI(i, c1, c2);
236 template <class C>
237 void
238 test_move()
240 #if TEST_STD_VER >= 11
241 C c;
242 typedef typename C::const_iterator CI;
244 MoveOnly mo(0);
245 typedef MoveOnly* I;
246 c.insert(c.end(), std::move_iterator<I>(&mo), std::move_iterator<I>(&mo+1));
248 int j = 0;
249 for (CI i = c.begin(); i != c.end(); ++i, ++j)
250 assert(*i == MoveOnly(j));
252 MoveOnly mo(1);
253 typedef input_iterator<MoveOnly*> I;
254 c.insert(c.end(), std::move_iterator<I>(I(&mo)), std::move_iterator<I>(I(&mo+1)));
256 j = 0;
257 for (CI i = c.begin(); i != c.end(); ++i, ++j)
258 assert(*i == MoveOnly(j));
259 #endif
262 int main(int, char**)
265 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
266 const int N = sizeof(rng)/sizeof(rng[0]);
267 for (int i = 0; i < N; ++i)
268 for (int j = 0; j < N; ++j)
269 for (int k = 0; k < N; ++k)
270 testN<std::deque<int> >(rng[i], rng[j], rng[k]);
271 testNI<std::deque<int> >(1500, 2000, 1000);
272 #if TEST_STD_VER >= 11
273 test_move<std::deque<MoveOnly, limited_allocator<MoveOnly, 2000> > >();
274 #endif
276 #if TEST_STD_VER >= 11
278 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
279 const int N = sizeof(rng)/sizeof(rng[0]);
280 for (int i = 0; i < N; ++i)
281 for (int j = 0; j < N; ++j)
282 for (int k = 0; k < N; ++k)
283 testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]);
284 testNI<std::deque<int> >(1500, 2000, 1000);
285 test_move<std::deque<MoveOnly, min_allocator<MoveOnly> > >();
287 #endif
289 return 0;