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