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