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<ForwardIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
12 // constexpr OutIter // constexpr after C++17
13 // rotate_copy(InIter first, InIter middle, InIter last, OutIter result);
18 #include "test_macros.h"
19 #include "test_iterators.h"
22 template <class InIter
, class OutIter
>
23 TEST_CONSTEXPR_CXX20
void test() {
24 int ia
[] = {0, 1, 2, 3};
25 const unsigned sa
= sizeof(ia
) / sizeof(ia
[0]);
28 OutIter r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
), OutIter(ib
));
29 assert(base(r
) == ib
);
31 r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
+ 1), OutIter(ib
));
32 assert(base(r
) == ib
+ 1);
35 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 1), InIter(ia
+ 1), OutIter(ib
));
36 assert(base(r
) == ib
+ 1);
39 r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
+ 2), OutIter(ib
));
40 assert(base(r
) == ib
+ 2);
44 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 1), InIter(ia
+ 2), OutIter(ib
));
45 assert(base(r
) == ib
+ 2);
49 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 2), InIter(ia
+ 2), OutIter(ib
));
50 assert(base(r
) == ib
+ 2);
54 r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
+ 3), OutIter(ib
));
55 assert(base(r
) == ib
+ 3);
60 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 1), InIter(ia
+ 3), OutIter(ib
));
61 assert(base(r
) == ib
+ 3);
66 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 2), InIter(ia
+ 3), OutIter(ib
));
67 assert(base(r
) == ib
+ 3);
72 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 3), InIter(ia
+ 3), OutIter(ib
));
73 assert(base(r
) == ib
+ 3);
78 r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
+ 4), OutIter(ib
));
79 assert(base(r
) == ib
+ 4);
85 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 1), InIter(ia
+ 4), OutIter(ib
));
86 assert(base(r
) == ib
+ 4);
92 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 2), InIter(ia
+ 4), OutIter(ib
));
93 assert(base(r
) == ib
+ 4);
99 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 3), InIter(ia
+ 4), OutIter(ib
));
100 assert(base(r
) == ib
+ 4);
106 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 4), InIter(ia
+ 4), OutIter(ib
));
107 assert(base(r
) == ib
+ 4);
114 int ints
[] = {1, 3, 5, 2, 5, 6};
115 int const n_ints
= sizeof(ints
)/sizeof(int);
116 int zeros
[n_ints
] = {0};
118 const std::size_t N
= 2;
119 const auto middle
= std::begin(ints
) + N
;
120 auto it
= std::rotate_copy(std::begin(ints
), middle
, std::end(ints
), std::begin(zeros
));
121 assert(std::distance(std::begin(zeros
), it
) == n_ints
);
122 assert(std::equal(std::begin(ints
), middle
, std::begin(zeros
) + n_ints
- N
));
123 assert(std::equal(middle
, std::end(ints
), std::begin(zeros
)));
127 TEST_CONSTEXPR_CXX20
bool all_tests() {
128 test
<bidirectional_iterator
<const int*>, cpp17_output_iterator
<int*> >();
129 test
<bidirectional_iterator
<const int*>, forward_iterator
<int*> >();
130 test
<bidirectional_iterator
<const int*>, bidirectional_iterator
<int*> >();
131 test
<bidirectional_iterator
<const int*>, random_access_iterator
<int*> >();
132 test
<bidirectional_iterator
<const int*>, int*>();
134 test
<random_access_iterator
<const int*>, cpp17_output_iterator
<int*> >();
135 test
<random_access_iterator
<const int*>, forward_iterator
<int*> >();
136 test
<random_access_iterator
<const int*>, bidirectional_iterator
<int*> >();
137 test
<random_access_iterator
<const int*>, random_access_iterator
<int*> >();
138 test
<random_access_iterator
<const int*>, int*>();
140 test
<const int*, cpp17_output_iterator
<int*> >();
141 test
<const int*, forward_iterator
<int*> >();
142 test
<const int*, bidirectional_iterator
<int*> >();
143 test
<const int*, random_access_iterator
<int*> >();
144 test
<const int*, int*>();
149 int main(int, char**) {
152 #if TEST_STD_VER > 17
153 static_assert(all_tests());