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