1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // REQUIRES: long_tests
13 // template <class InputIterator>
14 // iterator insert (const_iterator p, InputIterator f, InputIterator l);
20 #include "test_macros.h"
21 #include "test_iterators.h"
23 #include "test_allocator.h"
24 #include "min_allocator.h"
28 make(int size
, int start
= 0 )
30 const int b
= 4096 / sizeof(int);
34 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
39 for (int i
= 0; i
< init
-start
; ++i
)
41 for (int i
= 0; i
< size
; ++i
)
43 for (int i
= 0; i
< start
; ++i
)
50 test(int P
, const C
& c0
, const C
& c2
)
53 typedef typename
C::const_iterator CI
;
54 typedef input_iterator
<CI
> BCI
;
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());
62 for (int j
= 0; j
< P
; ++j
, ++i
)
64 for (int j
= 0; static_cast<std::size_t>(j
) < c2
.size(); ++j
, ++i
)
66 for (int j
= P
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
70 typedef typename
C::const_iterator CI
;
71 typedef forward_iterator
<CI
> BCI
;
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());
79 for (int j
= 0; j
< P
; ++j
, ++i
)
81 for (int j
= 0; static_cast<std::size_t>(j
) < c2
.size(); ++j
, ++i
)
83 for (int j
= P
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
87 typedef typename
C::const_iterator CI
;
88 typedef bidirectional_iterator
<CI
> BCI
;
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());
96 for (int j
= 0; j
< P
; ++j
, ++i
)
98 for (int j
= 0; static_cast<std::size_t>(j
) < c2
.size(); ++j
, ++i
)
100 for (int j
= P
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
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
);
118 for (int i
= M
-1; i
<= M
+1; ++i
)
120 if (0 <= i
&& i
<= N
)
122 C c1
= make
<C
>(N
, start
);
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
);
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
);
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
);
154 for (int i
= N
- 3; i
<= N
; ++i
)
156 if (0 <= i
&& i
<= N
)
158 C c1
= make
<C
>(N
, start
);
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());
177 for (int j
= 0; j
< P
; ++j
, ++i
)
179 for (int j
= 0; static_cast<std::size_t>(j
) < c2
.size(); ++j
, ++i
)
181 for (int j
= P
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
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
);
198 for (int i
= M
-1; i
<= M
+1; ++i
)
200 if (0 <= i
&& i
<= N
)
202 C c1
= make
<C
>(N
, start
);
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
);
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
);
225 for (int i
= N
- 3; i
<= N
; ++i
)
227 if (0 <= i
&& i
<= N
)
229 C c1
= make
<C
>(N
, start
);
240 #if TEST_STD_VER >= 11
242 typedef typename
C::const_iterator CI
;
246 c
.insert(c
.end(), std::move_iterator
<I
>(&mo
), std::move_iterator
<I
>(&mo
+1));
249 for (CI i
= c
.begin(); i
!= c
.end(); ++i
, ++j
)
250 assert(*i
== MoveOnly(j
));
253 typedef input_iterator
<MoveOnly
*> I
;
254 c
.insert(c
.end(), std::move_iterator
<I
>(I(&mo
)), std::move_iterator
<I
>(I(&mo
+1)));
257 for (CI i
= c
.begin(); i
!= c
.end(); ++i
, ++j
)
258 assert(*i
== MoveOnly(j
));
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> > >();
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
> > >();