1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <algorithm>
11
12 // template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
13 // constexpr OutIter // constexpr after C++17
14 // copy(InIter first, InIter last, OutIter result);
15
16 #include <algorithm>
17 #include <cassert>
18
19 #include "test_macros.h"
20 #include "test_iterators.h"
21
22 // #if TEST_STD_VER > 17
23 // TEST_CONSTEXPR bool test_constexpr() {
24 // int ia[] = {1, 2, 3, 4, 5};
25 // int ic[] = {6, 6, 6, 6, 6, 6, 6};
26 //
27 // auto p = std::copy(std::begin(ia), std::end(ia), std::begin(ic));
28 // return std::equal(std::begin(ia), std::end(ia), std::begin(ic), p)
29 // && std::all_of(p, std::end(ic), [](int a){return a == 6;})
30 // ;
31 // }
32 // #endif
33
34 template <class InIter, class OutIter>
35 void
test()36 test()
37 {
38 const unsigned N = 1000;
39 int ia[N];
40 for (unsigned i = 0; i < N; ++i)
41 ia[i] = i;
42 int ib[N] = {0};
43
44 OutIter r = std::copy(InIter(ia), InIter(ia+N), OutIter(ib));
45 assert(base(r) == ib+N);
46 for (unsigned i = 0; i < N; ++i)
47 assert(ia[i] == ib[i]);
48 }
49
main()50 int main()
51 {
52 test<input_iterator<const int*>, output_iterator<int*> >();
53 test<input_iterator<const int*>, input_iterator<int*> >();
54 test<input_iterator<const int*>, forward_iterator<int*> >();
55 test<input_iterator<const int*>, bidirectional_iterator<int*> >();
56 test<input_iterator<const int*>, random_access_iterator<int*> >();
57 test<input_iterator<const int*>, int*>();
58
59 test<forward_iterator<const int*>, output_iterator<int*> >();
60 test<forward_iterator<const int*>, input_iterator<int*> >();
61 test<forward_iterator<const int*>, forward_iterator<int*> >();
62 test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
63 test<forward_iterator<const int*>, random_access_iterator<int*> >();
64 test<forward_iterator<const int*>, int*>();
65
66 test<bidirectional_iterator<const int*>, output_iterator<int*> >();
67 test<bidirectional_iterator<const int*>, input_iterator<int*> >();
68 test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
69 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
70 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
71 test<bidirectional_iterator<const int*>, int*>();
72
73 test<random_access_iterator<const int*>, output_iterator<int*> >();
74 test<random_access_iterator<const int*>, input_iterator<int*> >();
75 test<random_access_iterator<const int*>, forward_iterator<int*> >();
76 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
77 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
78 test<random_access_iterator<const int*>, int*>();
79
80 test<const int*, output_iterator<int*> >();
81 test<const int*, input_iterator<int*> >();
82 test<const int*, forward_iterator<int*> >();
83 test<const int*, bidirectional_iterator<int*> >();
84 test<const int*, random_access_iterator<int*> >();
85 test<const int*, int*>();
86
87 // #if TEST_STD_VER > 17
88 // static_assert(test_constexpr());
89 // #endif
90 }
91