1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <algorithm>
11
12// template<ForwardIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
13//   OutIter
14//   rotate_copy(InIter first, InIter middle, InIter last, OutIter result);
15
16#include <algorithm>
17#include <cassert>
18
19#include "test_iterators.h"
20
21template <class InIter, class OutIter>
22void
23test()
24{
25    int ia[] = {0, 1, 2, 3};
26    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
27    int ib[sa] = {0};
28
29    OutIter r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia), OutIter(ib));
30    assert(base(r) == ib);
31
32    r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+1), OutIter(ib));
33    assert(base(r) == ib+1);
34    assert(ib[0] == 0);
35
36    r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+1), OutIter(ib));
37    assert(base(r) == ib+1);
38    assert(ib[0] == 0);
39
40    r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+2), OutIter(ib));
41    assert(base(r) == ib+2);
42    assert(ib[0] == 0);
43    assert(ib[1] == 1);
44
45    r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+2), OutIter(ib));
46    assert(base(r) == ib+2);
47    assert(ib[0] == 1);
48    assert(ib[1] == 0);
49
50    r = std::rotate_copy(InIter(ia), InIter(ia+2), InIter(ia+2), OutIter(ib));
51    assert(base(r) == ib+2);
52    assert(ib[0] == 0);
53    assert(ib[1] == 1);
54
55    r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+3), OutIter(ib));
56    assert(base(r) == ib+3);
57    assert(ib[0] == 0);
58    assert(ib[1] == 1);
59    assert(ib[2] == 2);
60
61    r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+3), OutIter(ib));
62    assert(base(r) == ib+3);
63    assert(ib[0] == 1);
64    assert(ib[1] == 2);
65    assert(ib[2] == 0);
66
67    r = std::rotate_copy(InIter(ia), InIter(ia+2), InIter(ia+3), OutIter(ib));
68    assert(base(r) == ib+3);
69    assert(ib[0] == 2);
70    assert(ib[1] == 0);
71    assert(ib[2] == 1);
72
73    r = std::rotate_copy(InIter(ia), InIter(ia+3), InIter(ia+3), OutIter(ib));
74    assert(base(r) == ib+3);
75    assert(ib[0] == 0);
76    assert(ib[1] == 1);
77    assert(ib[2] == 2);
78
79    r = std::rotate_copy(InIter(ia), InIter(ia), InIter(ia+4), OutIter(ib));
80    assert(base(r) == ib+4);
81    assert(ib[0] == 0);
82    assert(ib[1] == 1);
83    assert(ib[2] == 2);
84    assert(ib[3] == 3);
85
86    r = std::rotate_copy(InIter(ia), InIter(ia+1), InIter(ia+4), OutIter(ib));
87    assert(base(r) == ib+4);
88    assert(ib[0] == 1);
89    assert(ib[1] == 2);
90    assert(ib[2] == 3);
91    assert(ib[3] == 0);
92
93    r = std::rotate_copy(InIter(ia), InIter(ia+2), InIter(ia+4), OutIter(ib));
94    assert(base(r) == ib+4);
95    assert(ib[0] == 2);
96    assert(ib[1] == 3);
97    assert(ib[2] == 0);
98    assert(ib[3] == 1);
99
100    r = std::rotate_copy(InIter(ia), InIter(ia+3), InIter(ia+4), OutIter(ib));
101    assert(base(r) == ib+4);
102    assert(ib[0] == 3);
103    assert(ib[1] == 0);
104    assert(ib[2] == 1);
105    assert(ib[3] == 2);
106
107    r = std::rotate_copy(InIter(ia), InIter(ia+4), InIter(ia+4), OutIter(ib));
108    assert(base(r) == ib+4);
109    assert(ib[0] == 0);
110    assert(ib[1] == 1);
111    assert(ib[2] == 2);
112    assert(ib[3] == 3);
113}
114
115int main()
116{
117    test<bidirectional_iterator<const int*>, output_iterator<int*> >();
118    test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
119    test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
120    test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
121    test<bidirectional_iterator<const int*>, int*>();
122
123    test<random_access_iterator<const int*>, output_iterator<int*> >();
124    test<random_access_iterator<const int*>, forward_iterator<int*> >();
125    test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
126    test<random_access_iterator<const int*>, random_access_iterator<int*> >();
127    test<random_access_iterator<const int*>, int*>();
128
129    test<const int*, output_iterator<int*> >();
130    test<const int*, forward_iterator<int*> >();
131    test<const int*, bidirectional_iterator<int*> >();
132    test<const int*, random_access_iterator<int*> >();
133    test<const int*, int*>();
134}
135