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