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, typename OutIter>
13 // requires OutputIterator<OutIter, RvalueOf<InIter::reference>::type>
14 // OutIter
15 // move(InIter first, InIter last, OutIter result);
16
17 #include <algorithm>
18 #include <cassert>
19 #include <memory>
20
21 #include "test_macros.h"
22 #include "test_iterators.h"
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::move(InIter(ia), InIter(ia+N), OutIter(ib));
35 assert(base(r) == ib+N);
36 for (unsigned i = 0; i < N; ++i)
37 assert(ia[i] == ib[i]);
38 }
39
40 #if TEST_STD_VER >= 11
41 template <class InIter, class OutIter>
42 void
test1()43 test1()
44 {
45 const unsigned N = 100;
46 std::unique_ptr<int> ia[N];
47 for (unsigned i = 0; i < N; ++i)
48 ia[i].reset(new int(i));
49 std::unique_ptr<int> ib[N];
50
51 OutIter r = std::move(InIter(ia), InIter(ia+N), OutIter(ib));
52 assert(base(r) == ib+N);
53 for (unsigned i = 0; i < N; ++i)
54 assert(*ib[i] == static_cast<int>(i));
55 }
56 #endif
57
main()58 int main()
59 {
60 test<input_iterator<const int*>, output_iterator<int*> >();
61 test<input_iterator<const int*>, input_iterator<int*> >();
62 test<input_iterator<const int*>, forward_iterator<int*> >();
63 test<input_iterator<const int*>, bidirectional_iterator<int*> >();
64 test<input_iterator<const int*>, random_access_iterator<int*> >();
65 test<input_iterator<const int*>, int*>();
66
67 test<forward_iterator<const int*>, output_iterator<int*> >();
68 test<forward_iterator<const int*>, input_iterator<int*> >();
69 test<forward_iterator<const int*>, forward_iterator<int*> >();
70 test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
71 test<forward_iterator<const int*>, random_access_iterator<int*> >();
72 test<forward_iterator<const int*>, int*>();
73
74 test<bidirectional_iterator<const int*>, output_iterator<int*> >();
75 test<bidirectional_iterator<const int*>, input_iterator<int*> >();
76 test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
77 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
78 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
79 test<bidirectional_iterator<const int*>, int*>();
80
81 test<random_access_iterator<const int*>, output_iterator<int*> >();
82 test<random_access_iterator<const int*>, input_iterator<int*> >();
83 test<random_access_iterator<const int*>, forward_iterator<int*> >();
84 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
85 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
86 test<random_access_iterator<const int*>, int*>();
87
88 test<const int*, output_iterator<int*> >();
89 test<const int*, input_iterator<int*> >();
90 test<const int*, forward_iterator<int*> >();
91 test<const int*, bidirectional_iterator<int*> >();
92 test<const int*, random_access_iterator<int*> >();
93 test<const int*, int*>();
94
95 #if TEST_STD_VER >= 11
96 test1<input_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
97 test1<input_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
98 test1<input_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
99 test1<input_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
100 test1<input_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
101 test1<input_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
102
103 test1<forward_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
104 test1<forward_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
105 test1<forward_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
106 test1<forward_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
107 test1<forward_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
108 test1<forward_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
109
110 test1<bidirectional_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
111 test1<bidirectional_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
112 test1<bidirectional_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
113 test1<bidirectional_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
114 test1<bidirectional_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
115 test1<bidirectional_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
116
117 test1<random_access_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
118 test1<random_access_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
119 test1<random_access_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
120 test1<random_access_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
121 test1<random_access_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
122 test1<random_access_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
123
124 test1<std::unique_ptr<int>*, output_iterator<std::unique_ptr<int>*> >();
125 test1<std::unique_ptr<int>*, input_iterator<std::unique_ptr<int>*> >();
126 test1<std::unique_ptr<int>*, forward_iterator<std::unique_ptr<int>*> >();
127 test1<std::unique_ptr<int>*, bidirectional_iterator<std::unique_ptr<int>*> >();
128 test1<std::unique_ptr<int>*, random_access_iterator<std::unique_ptr<int>*> >();
129 test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
130 #endif // TEST_STD_VER >= 11
131 }
132