[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.reverse / reverse_copy.pass.cpp
blobbe3e6afd0472a48ad27b31f165afe58b40337e0e
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <algorithm>
11 // template<BidirectionalIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
12 // constexpr OutIter // constexpr after C++17
13 // reverse_copy(InIter first, InIter last, OutIter result);
15 #include <algorithm>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "test_iterators.h"
21 #if TEST_STD_VER > 17
22 TEST_CONSTEXPR bool test_constexpr() {
23 int ia[] = {1, 3, 5, 2, 5, 6};
24 int ib[std::size(ia)] = {0};
26 auto it = std::reverse_copy(std::begin(ia), std::end(ia), std::begin(ib));
28 return std::distance(std::begin(ib), it) == static_cast<int>(std::size(ia))
29 && std::equal (std::begin(ia), std::end(ia), std::rbegin(ib))
32 #endif
34 template <class InIter, class OutIter>
35 void
36 test()
38 const int ia[] = {0};
39 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
40 int ja[sa] = {-1};
41 OutIter r = std::reverse_copy(InIter(ia), InIter(ia), OutIter(ja));
42 assert(base(r) == ja);
43 assert(ja[0] == -1);
44 r = std::reverse_copy(InIter(ia), InIter(ia+sa), OutIter(ja));
45 assert(ja[0] == 0);
47 const int ib[] = {0, 1};
48 const unsigned sb = sizeof(ib)/sizeof(ib[0]);
49 int jb[sb] = {-1};
50 r = std::reverse_copy(InIter(ib), InIter(ib+sb), OutIter(jb));
51 assert(base(r) == jb+sb);
52 assert(jb[0] == 1);
53 assert(jb[1] == 0);
55 const int ic[] = {0, 1, 2};
56 const unsigned sc = sizeof(ic)/sizeof(ic[0]);
57 int jc[sc] = {-1};
58 r = std::reverse_copy(InIter(ic), InIter(ic+sc), OutIter(jc));
59 assert(base(r) == jc+sc);
60 assert(jc[0] == 2);
61 assert(jc[1] == 1);
62 assert(jc[2] == 0);
64 int id[] = {0, 1, 2, 3};
65 const unsigned sd = sizeof(id)/sizeof(id[0]);
66 int jd[sd] = {-1};
67 r = std::reverse_copy(InIter(id), InIter(id+sd), OutIter(jd));
68 assert(base(r) == jd+sd);
69 assert(jd[0] == 3);
70 assert(jd[1] == 2);
71 assert(jd[2] == 1);
72 assert(jd[3] == 0);
75 int main(int, char**)
77 test<bidirectional_iterator<const int*>, output_iterator<int*> >();
78 test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
79 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
80 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
81 test<bidirectional_iterator<const int*>, int*>();
83 test<random_access_iterator<const int*>, output_iterator<int*> >();
84 test<random_access_iterator<const int*>, forward_iterator<int*> >();
85 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
86 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
87 test<random_access_iterator<const int*>, int*>();
89 test<const int*, output_iterator<int*> >();
90 test<const int*, forward_iterator<int*> >();
91 test<const int*, bidirectional_iterator<int*> >();
92 test<const int*, random_access_iterator<int*> >();
93 test<const int*, int*>();
95 #if TEST_STD_VER > 17
96 static_assert(test_constexpr());
97 #endif
99 return 0;