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 //===----------------------------------------------------------------------===//
11 // template<ShuffleIterator Iter>
13 // rotate(Iter first, Iter middle, Iter last);
19 #include "test_macros.h"
20 #include "test_iterators.h"
23 TEST_CONSTEXPR_CXX17
bool
27 const int sa
= static_cast<int>(sizeof(ia
)/sizeof(ia
[0]));
28 Iter r
= std::rotate(Iter(ia
), Iter(ia
), Iter(ia
));
29 assert(base(r
) == ia
);
31 r
= std::rotate(Iter(ia
), Iter(ia
), Iter(ia
+sa
));
32 assert(base(r
) == ia
+sa
);
34 r
= std::rotate(Iter(ia
), Iter(ia
+sa
), Iter(ia
+sa
));
35 assert(base(r
) == ia
);
39 const int sb
= static_cast<int>(sizeof(ib
)/sizeof(ib
[0]));
40 r
= std::rotate(Iter(ib
), Iter(ib
), Iter(ib
+sb
));
41 assert(base(r
) == ib
+sb
);
44 r
= std::rotate(Iter(ib
), Iter(ib
+1), Iter(ib
+sb
));
45 assert(base(r
) == ib
+1);
48 r
= std::rotate(Iter(ib
), Iter(ib
+sb
), Iter(ib
+sb
));
49 assert(base(r
) == ib
);
54 const int sc
= static_cast<int>(sizeof(ic
)/sizeof(ic
[0]));
55 r
= std::rotate(Iter(ic
), Iter(ic
), Iter(ic
+sc
));
56 assert(base(r
) == ic
+sc
);
60 r
= std::rotate(Iter(ic
), Iter(ic
+1), Iter(ic
+sc
));
61 assert(base(r
) == ic
+2);
65 r
= std::rotate(Iter(ic
), Iter(ic
+2), Iter(ic
+sc
));
66 assert(base(r
) == ic
+1);
70 r
= std::rotate(Iter(ic
), Iter(ic
+sc
), Iter(ic
+sc
));
71 assert(base(r
) == ic
);
76 int id
[] = {0, 1, 2, 3};
77 const int sd
= static_cast<int>(sizeof(id
)/sizeof(id
[0]));
78 r
= std::rotate(Iter(id
), Iter(id
), Iter(id
+sd
));
79 assert(base(r
) == id
+sd
);
84 r
= std::rotate(Iter(id
), Iter(id
+1), Iter(id
+sd
));
85 assert(base(r
) == id
+3);
90 r
= std::rotate(Iter(id
), Iter(id
+2), Iter(id
+sd
));
91 assert(base(r
) == id
+2);
96 r
= std::rotate(Iter(id
), Iter(id
+3), Iter(id
+sd
));
97 assert(base(r
) == id
+1);
102 r
= std::rotate(Iter(id
), Iter(id
+sd
), Iter(id
+sd
));
103 assert(base(r
) == id
);
109 int ie
[] = {0, 1, 2, 3, 4};
110 const int se
= static_cast<int>(sizeof(ie
)/sizeof(ie
[0]));
111 r
= std::rotate(Iter(ie
), Iter(ie
), Iter(ie
+se
));
112 assert(base(r
) == ie
+se
);
118 r
= std::rotate(Iter(ie
), Iter(ie
+1), Iter(ie
+se
));
119 assert(base(r
) == ie
+4);
125 r
= std::rotate(Iter(ie
), Iter(ie
+2), Iter(ie
+se
));
126 assert(base(r
) == ie
+3);
132 r
= std::rotate(Iter(ie
), Iter(ie
+3), Iter(ie
+se
));
133 assert(base(r
) == ie
+2);
139 r
= std::rotate(Iter(ie
), Iter(ie
+4), Iter(ie
+se
));
140 assert(base(r
) == ie
+1);
146 r
= std::rotate(Iter(ie
), Iter(ie
+se
), Iter(ie
+se
));
147 assert(base(r
) == ie
);
154 int ig
[] = {0, 1, 2, 3, 4, 5};
155 const int sg
= static_cast<int>(sizeof(ig
)/sizeof(ig
[0]));
156 r
= std::rotate(Iter(ig
), Iter(ig
), Iter(ig
+sg
));
157 assert(base(r
) == ig
+sg
);
164 r
= std::rotate(Iter(ig
), Iter(ig
+1), Iter(ig
+sg
));
165 assert(base(r
) == ig
+5);
172 r
= std::rotate(Iter(ig
), Iter(ig
+2), Iter(ig
+sg
));
173 assert(base(r
) == ig
+4);
180 r
= std::rotate(Iter(ig
), Iter(ig
+3), Iter(ig
+sg
));
181 assert(base(r
) == ig
+3);
188 r
= std::rotate(Iter(ig
), Iter(ig
+4), Iter(ig
+sg
));
189 assert(base(r
) == ig
+2);
196 r
= std::rotate(Iter(ig
), Iter(ig
+5), Iter(ig
+sg
));
197 assert(base(r
) == ig
+1);
204 r
= std::rotate(Iter(ig
), Iter(ig
+sg
), Iter(ig
+sg
));
205 assert(base(r
) == ig
);
216 #if TEST_STD_VER >= 11
218 template <class Iter
>
222 std::unique_ptr
<int> ia
[1];
223 const int sa
= static_cast<int>(sizeof(ia
)/sizeof(ia
[0]));
224 for (int i
= 0; i
< sa
; ++i
)
225 ia
[i
].reset(new int(i
));
226 Iter r
= std::rotate(Iter(ia
), Iter(ia
), Iter(ia
));
227 assert(base(r
) == ia
);
229 r
= std::rotate(Iter(ia
), Iter(ia
), Iter(ia
+sa
));
230 assert(base(r
) == ia
+sa
);
232 r
= std::rotate(Iter(ia
), Iter(ia
+sa
), Iter(ia
+sa
));
233 assert(base(r
) == ia
);
236 std::unique_ptr
<int> ib
[2];
237 const int sb
= static_cast<int>(sizeof(ib
)/sizeof(ib
[0]));
238 for (int i
= 0; i
< sb
; ++i
)
239 ib
[i
].reset(new int(i
));
240 r
= std::rotate(Iter(ib
), Iter(ib
), Iter(ib
+sb
));
241 assert(base(r
) == ib
+sb
);
244 r
= std::rotate(Iter(ib
), Iter(ib
+1), Iter(ib
+sb
));
245 assert(base(r
) == ib
+1);
248 r
= std::rotate(Iter(ib
), Iter(ib
+sb
), Iter(ib
+sb
));
249 assert(base(r
) == ib
);
253 std::unique_ptr
<int> ic
[3];
254 const int sc
= static_cast<int>(sizeof(ic
)/sizeof(ic
[0]));
255 for (int i
= 0; i
< sc
; ++i
)
256 ic
[i
].reset(new int(i
));
257 r
= std::rotate(Iter(ic
), Iter(ic
), Iter(ic
+sc
));
258 assert(base(r
) == ic
+sc
);
262 r
= std::rotate(Iter(ic
), Iter(ic
+1), Iter(ic
+sc
));
263 assert(base(r
) == ic
+2);
267 r
= std::rotate(Iter(ic
), Iter(ic
+2), Iter(ic
+sc
));
268 assert(base(r
) == ic
+1);
272 r
= std::rotate(Iter(ic
), Iter(ic
+sc
), Iter(ic
+sc
));
273 assert(base(r
) == ic
);
278 std::unique_ptr
<int> id
[4];
279 const int sd
= static_cast<int>(sizeof(id
)/sizeof(id
[0]));
280 for (int i
= 0; i
< sd
; ++i
)
281 id
[i
].reset(new int(i
));
282 r
= std::rotate(Iter(id
), Iter(id
), Iter(id
+sd
));
283 assert(base(r
) == id
+sd
);
288 r
= std::rotate(Iter(id
), Iter(id
+1), Iter(id
+sd
));
289 assert(base(r
) == id
+3);
294 r
= std::rotate(Iter(id
), Iter(id
+2), Iter(id
+sd
));
295 assert(base(r
) == id
+2);
300 r
= std::rotate(Iter(id
), Iter(id
+3), Iter(id
+sd
));
301 assert(base(r
) == id
+1);
306 r
= std::rotate(Iter(id
), Iter(id
+sd
), Iter(id
+sd
));
307 assert(base(r
) == id
);
313 std::unique_ptr
<int> ie
[5];
314 const int se
= static_cast<int>(sizeof(ie
)/sizeof(ie
[0]));
315 for (int i
= 0; i
< se
; ++i
)
316 ie
[i
].reset(new int(i
));
317 r
= std::rotate(Iter(ie
), Iter(ie
), Iter(ie
+se
));
318 assert(base(r
) == ie
+se
);
324 r
= std::rotate(Iter(ie
), Iter(ie
+1), Iter(ie
+se
));
325 assert(base(r
) == ie
+4);
331 r
= std::rotate(Iter(ie
), Iter(ie
+2), Iter(ie
+se
));
332 assert(base(r
) == ie
+3);
338 r
= std::rotate(Iter(ie
), Iter(ie
+3), Iter(ie
+se
));
339 assert(base(r
) == ie
+2);
345 r
= std::rotate(Iter(ie
), Iter(ie
+4), Iter(ie
+se
));
346 assert(base(r
) == ie
+1);
352 r
= std::rotate(Iter(ie
), Iter(ie
+se
), Iter(ie
+se
));
353 assert(base(r
) == ie
);
360 std::unique_ptr
<int> ig
[6];
361 const int sg
= static_cast<int>(sizeof(ig
)/sizeof(ig
[0]));
362 for (int i
= 0; i
< sg
; ++i
)
363 ig
[i
].reset(new int(i
));
364 r
= std::rotate(Iter(ig
), Iter(ig
), Iter(ig
+sg
));
365 assert(base(r
) == ig
+sg
);
372 r
= std::rotate(Iter(ig
), Iter(ig
+1), Iter(ig
+sg
));
373 assert(base(r
) == ig
+5);
380 r
= std::rotate(Iter(ig
), Iter(ig
+2), Iter(ig
+sg
));
381 assert(base(r
) == ig
+4);
388 r
= std::rotate(Iter(ig
), Iter(ig
+3), Iter(ig
+sg
));
389 assert(base(r
) == ig
+3);
396 r
= std::rotate(Iter(ig
), Iter(ig
+4), Iter(ig
+sg
));
397 assert(base(r
) == ig
+2);
404 r
= std::rotate(Iter(ig
), Iter(ig
+5), Iter(ig
+sg
));
405 assert(base(r
) == ig
+1);
412 r
= std::rotate(Iter(ig
), Iter(ig
+sg
), Iter(ig
+sg
));
413 assert(base(r
) == ig
);
422 #endif // TEST_STD_VER >= 11
424 int main(int, char**)
426 test
<forward_iterator
<int*> >();
427 test
<bidirectional_iterator
<int*> >();
428 test
<random_access_iterator
<int*> >();
431 #if TEST_STD_VER >= 11
433 test1
<forward_iterator
<std::unique_ptr
<int>*> >();
434 test1
<bidirectional_iterator
<std::unique_ptr
<int>*> >();
435 test1
<random_access_iterator
<std::unique_ptr
<int>*> >();
436 test1
<std::unique_ptr
<int>*>();
440 #if TEST_STD_VER > 17
441 static_assert(test
<forward_iterator
<int*> >());
442 static_assert(test
<bidirectional_iterator
<int*> >());
443 static_assert(test
<random_access_iterator
<int*> >());
444 static_assert(test
<int*>());
445 #endif // TEST_STD_VER > 17