xref: /llvm-project/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp (revision 2df59c50688c122bbcae7467d3eaf862c3ea3088)
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 // #if TEST_STD_VER > 17
22 // TEST_CONSTEXPR bool test_constexpr() {
23 //     int ia[] = {1, 2, 3, 4, 5};
24 //     int ic[] = {6, 6, 6, 6, 6, 6, 6};
25 //
26 //     auto p = std::copy(std::begin(ia), std::end(ia), std::begin(ic));
27 //     return std::equal(std::begin(ia), std::end(ia), std::begin(ic), p)
28 //         && std::all_of(p, std::end(ic), [](int a){return a == 6;})
29 //         ;
30 //     }
31 // #endif
32 
33 template <class InIter, class OutIter>
34 void
35 test()
36 {
37     const unsigned N = 1000;
38     int ia[N];
39     for (unsigned i = 0; i < N; ++i)
40         ia[i] = i;
41     int ib[N] = {0};
42 
43     OutIter r = std::copy(InIter(ia), InIter(ia+N), OutIter(ib));
44     assert(base(r) == ib+N);
45     for (unsigned i = 0; i < N; ++i)
46         assert(ia[i] == ib[i]);
47 }
48 
49 int main(int, char**)
50 {
51     test<input_iterator<const int*>, output_iterator<int*> >();
52     test<input_iterator<const int*>, input_iterator<int*> >();
53     test<input_iterator<const int*>, forward_iterator<int*> >();
54     test<input_iterator<const int*>, bidirectional_iterator<int*> >();
55     test<input_iterator<const int*>, random_access_iterator<int*> >();
56     test<input_iterator<const int*>, int*>();
57 
58     test<forward_iterator<const int*>, output_iterator<int*> >();
59     test<forward_iterator<const int*>, input_iterator<int*> >();
60     test<forward_iterator<const int*>, forward_iterator<int*> >();
61     test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
62     test<forward_iterator<const int*>, random_access_iterator<int*> >();
63     test<forward_iterator<const int*>, int*>();
64 
65     test<bidirectional_iterator<const int*>, output_iterator<int*> >();
66     test<bidirectional_iterator<const int*>, input_iterator<int*> >();
67     test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
68     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
69     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
70     test<bidirectional_iterator<const int*>, int*>();
71 
72     test<random_access_iterator<const int*>, output_iterator<int*> >();
73     test<random_access_iterator<const int*>, input_iterator<int*> >();
74     test<random_access_iterator<const int*>, forward_iterator<int*> >();
75     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
76     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
77     test<random_access_iterator<const int*>, int*>();
78 
79     test<const int*, output_iterator<int*> >();
80     test<const int*, input_iterator<int*> >();
81     test<const int*, forward_iterator<int*> >();
82     test<const int*, bidirectional_iterator<int*> >();
83     test<const int*, random_access_iterator<int*> >();
84     test<const int*, int*>();
85 
86 // #if TEST_STD_VER > 17
87 //     static_assert(test_constexpr());
88 // #endif
89 
90   return 0;
91 }
92