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<BidirectionalIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
12 // constexpr OutIter // constexpr after C++17
13 // reverse_copy(InIter first, InIter last, OutIter result);
18 #include "test_macros.h"
19 #include "test_iterators.h"
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
))
34 template <class InIter
, class OutIter
>
39 const unsigned sa
= sizeof(ia
)/sizeof(ia
[0]);
41 OutIter r
= std::reverse_copy(InIter(ia
), InIter(ia
), OutIter(ja
));
42 assert(base(r
) == ja
);
44 r
= std::reverse_copy(InIter(ia
), InIter(ia
+sa
), OutIter(ja
));
47 const int ib
[] = {0, 1};
48 const unsigned sb
= sizeof(ib
)/sizeof(ib
[0]);
50 r
= std::reverse_copy(InIter(ib
), InIter(ib
+sb
), OutIter(jb
));
51 assert(base(r
) == jb
+sb
);
55 const int ic
[] = {0, 1, 2};
56 const unsigned sc
= sizeof(ic
)/sizeof(ic
[0]);
58 r
= std::reverse_copy(InIter(ic
), InIter(ic
+sc
), OutIter(jc
));
59 assert(base(r
) == jc
+sc
);
64 int id
[] = {0, 1, 2, 3};
65 const unsigned sd
= sizeof(id
)/sizeof(id
[0]);
67 r
= std::reverse_copy(InIter(id
), InIter(id
+sd
), OutIter(jd
));
68 assert(base(r
) == jd
+sd
);
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*>();
96 static_assert(test_constexpr());