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);
15 // Older compilers don't support std::is_constant_evaluated
16 // UNSUPPORTED: clang-4, clang-5, clang-6, clang-7, clang-8
17 // UNSUPPORTED: apple-clang-9, apple-clang-10
22 #include "test_macros.h"
23 #include "test_iterators.h"
26 template <class InIter
, class OutIter
>
27 TEST_CONSTEXPR_CXX20
void test() {
28 int ia
[] = {0, 1, 2, 3};
29 const unsigned sa
= sizeof(ia
) / sizeof(ia
[0]);
32 OutIter r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
), OutIter(ib
));
33 assert(base(r
) == ib
);
35 r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
+ 1), OutIter(ib
));
36 assert(base(r
) == ib
+ 1);
39 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 1), InIter(ia
+ 1), OutIter(ib
));
40 assert(base(r
) == ib
+ 1);
43 r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
+ 2), OutIter(ib
));
44 assert(base(r
) == ib
+ 2);
48 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 1), InIter(ia
+ 2), OutIter(ib
));
49 assert(base(r
) == ib
+ 2);
53 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 2), InIter(ia
+ 2), OutIter(ib
));
54 assert(base(r
) == ib
+ 2);
58 r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
+ 3), OutIter(ib
));
59 assert(base(r
) == ib
+ 3);
64 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 1), InIter(ia
+ 3), OutIter(ib
));
65 assert(base(r
) == ib
+ 3);
70 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 2), InIter(ia
+ 3), OutIter(ib
));
71 assert(base(r
) == ib
+ 3);
76 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 3), InIter(ia
+ 3), OutIter(ib
));
77 assert(base(r
) == ib
+ 3);
82 r
= std::rotate_copy(InIter(ia
), InIter(ia
), InIter(ia
+ 4), OutIter(ib
));
83 assert(base(r
) == ib
+ 4);
89 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 1), InIter(ia
+ 4), OutIter(ib
));
90 assert(base(r
) == ib
+ 4);
96 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 2), InIter(ia
+ 4), OutIter(ib
));
97 assert(base(r
) == ib
+ 4);
103 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 3), InIter(ia
+ 4), OutIter(ib
));
104 assert(base(r
) == ib
+ 4);
110 r
= std::rotate_copy(InIter(ia
), InIter(ia
+ 4), InIter(ia
+ 4), OutIter(ib
));
111 assert(base(r
) == ib
+ 4);
118 int ints
[] = {1, 3, 5, 2, 5, 6};
119 int const n_ints
= sizeof(ints
)/sizeof(int);
120 int zeros
[n_ints
] = {0};
123 const auto middle
= std::begin(ints
) + N
;
124 auto it
= std::rotate_copy(std::begin(ints
), middle
, std::end(ints
), std::begin(zeros
));
125 assert(std::distance(std::begin(zeros
), it
) == n_ints
);
126 assert(std::equal(std::begin(ints
), middle
, std::begin(zeros
) + n_ints
- N
));
127 assert(std::equal(middle
, std::end(ints
), std::begin(zeros
)));
131 TEST_CONSTEXPR_CXX20
bool all_tests() {
132 test
<bidirectional_iterator
<const int*>, output_iterator
<int*> >();
133 test
<bidirectional_iterator
<const int*>, forward_iterator
<int*> >();
134 test
<bidirectional_iterator
<const int*>, bidirectional_iterator
<int*> >();
135 test
<bidirectional_iterator
<const int*>, random_access_iterator
<int*> >();
136 test
<bidirectional_iterator
<const int*>, int*>();
138 test
<random_access_iterator
<const int*>, output_iterator
<int*> >();
139 test
<random_access_iterator
<const int*>, forward_iterator
<int*> >();
140 test
<random_access_iterator
<const int*>, bidirectional_iterator
<int*> >();
141 test
<random_access_iterator
<const int*>, random_access_iterator
<int*> >();
142 test
<random_access_iterator
<const int*>, int*>();
144 test
<const int*, output_iterator
<int*> >();
145 test
<const int*, forward_iterator
<int*> >();
146 test
<const int*, bidirectional_iterator
<int*> >();
147 test
<const int*, random_access_iterator
<int*> >();
148 test
<const int*, int*>();
153 int main(int, char**) {
156 #if TEST_STD_VER > 17
157 static_assert(all_tests());