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_n(InIter first, InIter::difference_type n, OutIter result);
15
16 #include <algorithm>
17 #include <cassert>
18
19 #include "test_macros.h"
20 #include "test_iterators.h"
21 #include "user_defined_integral.hpp"
22
23 // #if TEST_STD_VER > 17
24 // TEST_CONSTEXPR bool test_constexpr() {
25 // int ia[] = {1, 2, 3, 4, 5};
26 // int ic[] = {6, 6, 6, 6, 6, 6, 6};
27 //
28 // auto p = std::copy_n(std::begin(ia), 4, std::begin(ic));
29 // return std::equal(std::begin(ic), p, std::begin(ia))
30 // && std::all_of(p, std::end(ic), [](int a){return a == 6;})
31 // ;
32 // }
33 // #endif
34
35 typedef UserDefinedIntegral<unsigned> UDI;
36
37 template <class InIter, class OutIter>
38 void
test()39 test()
40 {
41 const unsigned N = 1000;
42 int ia[N];
43 for (unsigned i = 0; i < N; ++i)
44 ia[i] = i;
45 int ib[N] = {0};
46
47 OutIter r = std::copy_n(InIter(ia), UDI(N/2), OutIter(ib));
48 assert(base(r) == ib+N/2);
49 for (unsigned i = 0; i < N/2; ++i)
50 assert(ia[i] == ib[i]);
51 }
52
main()53 int main()
54 {
55 test<input_iterator<const int*>, output_iterator<int*> >();
56 test<input_iterator<const int*>, input_iterator<int*> >();
57 test<input_iterator<const int*>, forward_iterator<int*> >();
58 test<input_iterator<const int*>, bidirectional_iterator<int*> >();
59 test<input_iterator<const int*>, random_access_iterator<int*> >();
60 test<input_iterator<const int*>, int*>();
61
62 test<forward_iterator<const int*>, output_iterator<int*> >();
63 test<forward_iterator<const int*>, input_iterator<int*> >();
64 test<forward_iterator<const int*>, forward_iterator<int*> >();
65 test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
66 test<forward_iterator<const int*>, random_access_iterator<int*> >();
67 test<forward_iterator<const int*>, int*>();
68
69 test<bidirectional_iterator<const int*>, output_iterator<int*> >();
70 test<bidirectional_iterator<const int*>, input_iterator<int*> >();
71 test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
72 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
73 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
74 test<bidirectional_iterator<const int*>, int*>();
75
76 test<random_access_iterator<const int*>, output_iterator<int*> >();
77 test<random_access_iterator<const int*>, input_iterator<int*> >();
78 test<random_access_iterator<const int*>, forward_iterator<int*> >();
79 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
80 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
81 test<random_access_iterator<const int*>, int*>();
82
83 test<const int*, output_iterator<int*> >();
84 test<const int*, input_iterator<int*> >();
85 test<const int*, forward_iterator<int*> >();
86 test<const int*, bidirectional_iterator<int*> >();
87 test<const int*, random_access_iterator<int*> >();
88 test<const int*, int*>();
89
90 // #if TEST_STD_VER > 17
91 // static_assert(test_constexpr());
92 // #endif
93 }
94