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 //===----------------------------------------------------------------------===//
8
9 // <algorithm>
10
11 // template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
12 // constexpr OutIter // constexpr after C++17
13 // copy(InIter first, InIter last, OutIter result);
14
15 #include <algorithm>
16 #include <cassert>
17
18 #include "test_macros.h"
19 #include "test_iterators.h"
20
21 template <class InIter, class OutIter>
22 TEST_CONSTEXPR_CXX20 void
test_copy()23 test_copy()
24 {
25 const unsigned N = 1000;
26 int ia[N] = {};
27 for (unsigned i = 0; i < N; ++i)
28 ia[i] = i;
29 int ib[N] = {0};
30
31 OutIter r = std::copy(InIter(ia), InIter(ia+N), OutIter(ib));
32 assert(base(r) == ib+N);
33 for (unsigned i = 0; i < N; ++i)
34 assert(ia[i] == ib[i]);
35 }
36
37 TEST_CONSTEXPR_CXX20 bool
test()38 test()
39 {
40 test_copy<cpp17_input_iterator<const int*>, cpp17_output_iterator<int*> >();
41 test_copy<cpp17_input_iterator<const int*>, forward_iterator<int*> >();
42 test_copy<cpp17_input_iterator<const int*>, bidirectional_iterator<int*> >();
43 test_copy<cpp17_input_iterator<const int*>, random_access_iterator<int*> >();
44 test_copy<cpp17_input_iterator<const int*>, int*>();
45
46 test_copy<forward_iterator<const int*>, cpp17_output_iterator<int*> >();
47 test_copy<forward_iterator<const int*>, forward_iterator<int*> >();
48 test_copy<forward_iterator<const int*>, bidirectional_iterator<int*> >();
49 test_copy<forward_iterator<const int*>, random_access_iterator<int*> >();
50 test_copy<forward_iterator<const int*>, int*>();
51
52 test_copy<bidirectional_iterator<const int*>, cpp17_output_iterator<int*> >();
53 test_copy<bidirectional_iterator<const int*>, forward_iterator<int*> >();
54 test_copy<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
55 test_copy<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
56 test_copy<bidirectional_iterator<const int*>, int*>();
57
58 test_copy<random_access_iterator<const int*>, cpp17_output_iterator<int*> >();
59 test_copy<random_access_iterator<const int*>, forward_iterator<int*> >();
60 test_copy<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
61 test_copy<random_access_iterator<const int*>, random_access_iterator<int*> >();
62 test_copy<random_access_iterator<const int*>, int*>();
63
64 test_copy<const int*, cpp17_output_iterator<int*> >();
65 test_copy<const int*, forward_iterator<int*> >();
66 test_copy<const int*, bidirectional_iterator<int*> >();
67 test_copy<const int*, random_access_iterator<int*> >();
68 test_copy<const int*, int*>();
69
70 #if TEST_STD_VER > 17
71 test_copy<cpp17_input_iterator<const int*>, contiguous_iterator<int*>>();
72 test_copy<forward_iterator<const int*>, contiguous_iterator<int*>>();
73 test_copy<bidirectional_iterator<const int*>, contiguous_iterator<int*>>();
74 test_copy<random_access_iterator<const int*>, contiguous_iterator<int*>>();
75 test_copy<const int*, contiguous_iterator<int*>>();
76
77 test_copy<contiguous_iterator<const int*>, cpp17_output_iterator<int*>>();
78 test_copy<contiguous_iterator<const int*>, forward_iterator<int*>>();
79 test_copy<contiguous_iterator<const int*>, bidirectional_iterator<int*>>();
80 test_copy<contiguous_iterator<const int*>, random_access_iterator<int*>>();
81 test_copy<contiguous_iterator<const int*>, int*>();
82 #endif
83
84 return true;
85 }
86
main(int,char **)87 int main(int, char**)
88 {
89 test();
90
91 #if TEST_STD_VER > 17
92 static_assert(test());
93 #endif
94
95 return 0;
96 }
97