• 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, 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 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
20 #include <memory>
21 #endif
22 
23 #include "test_iterators.h"
24 
25 template <class InIter, class OutIter>
26 void
test()27 test()
28 {
29     const unsigned N = 1000;
30     int ia[N];
31     for (unsigned i = 0; i < N; ++i)
32         ia[i] = i;
33     int ib[N] = {0};
34 
35     OutIter r = std::move(InIter(ia), InIter(ia+N), OutIter(ib));
36     assert(base(r) == ib+N);
37     for (unsigned i = 0; i < N; ++i)
38         assert(ia[i] == ib[i]);
39 }
40 
41 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
42 
43 template <class InIter, class OutIter>
44 void
test1()45 test1()
46 {
47     const unsigned N = 100;
48     std::unique_ptr<int> ia[N];
49     for (unsigned i = 0; i < N; ++i)
50         ia[i].reset(new int(i));
51     std::unique_ptr<int> ib[N];
52 
53     OutIter r = std::move(InIter(ia), InIter(ia+N), OutIter(ib));
54     assert(base(r) == ib+N);
55     for (unsigned i = 0; i < N; ++i)
56         assert(*ib[i] == i);
57 }
58 
59 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
60 
main()61 int main()
62 {
63     test<input_iterator<const int*>, output_iterator<int*> >();
64     test<input_iterator<const int*>, input_iterator<int*> >();
65     test<input_iterator<const int*>, forward_iterator<int*> >();
66     test<input_iterator<const int*>, bidirectional_iterator<int*> >();
67     test<input_iterator<const int*>, random_access_iterator<int*> >();
68     test<input_iterator<const int*>, int*>();
69 
70     test<forward_iterator<const int*>, output_iterator<int*> >();
71     test<forward_iterator<const int*>, input_iterator<int*> >();
72     test<forward_iterator<const int*>, forward_iterator<int*> >();
73     test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
74     test<forward_iterator<const int*>, random_access_iterator<int*> >();
75     test<forward_iterator<const int*>, int*>();
76 
77     test<bidirectional_iterator<const int*>, output_iterator<int*> >();
78     test<bidirectional_iterator<const int*>, input_iterator<int*> >();
79     test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
80     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
81     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
82     test<bidirectional_iterator<const int*>, int*>();
83 
84     test<random_access_iterator<const int*>, output_iterator<int*> >();
85     test<random_access_iterator<const int*>, input_iterator<int*> >();
86     test<random_access_iterator<const int*>, forward_iterator<int*> >();
87     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
88     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
89     test<random_access_iterator<const int*>, int*>();
90 
91     test<const int*, output_iterator<int*> >();
92     test<const int*, input_iterator<int*> >();
93     test<const int*, forward_iterator<int*> >();
94     test<const int*, bidirectional_iterator<int*> >();
95     test<const int*, random_access_iterator<int*> >();
96     test<const int*, int*>();
97 
98 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
99     test1<input_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
100     test1<input_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
101     test1<input_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
102     test1<input_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
103     test1<input_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
104     test1<input_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
105 
106     test1<forward_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
107     test1<forward_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
108     test1<forward_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
109     test1<forward_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
110     test1<forward_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
111     test1<forward_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
112 
113     test1<bidirectional_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
114     test1<bidirectional_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
115     test1<bidirectional_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
116     test1<bidirectional_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
117     test1<bidirectional_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
118     test1<bidirectional_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
119 
120     test1<random_access_iterator<std::unique_ptr<int>*>, output_iterator<std::unique_ptr<int>*> >();
121     test1<random_access_iterator<std::unique_ptr<int>*>, input_iterator<std::unique_ptr<int>*> >();
122     test1<random_access_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
123     test1<random_access_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
124     test1<random_access_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
125     test1<random_access_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
126 
127     test1<std::unique_ptr<int>*, output_iterator<std::unique_ptr<int>*> >();
128     test1<std::unique_ptr<int>*, input_iterator<std::unique_ptr<int>*> >();
129     test1<std::unique_ptr<int>*, forward_iterator<std::unique_ptr<int>*> >();
130     test1<std::unique_ptr<int>*, bidirectional_iterator<std::unique_ptr<int>*> >();
131     test1<std::unique_ptr<int>*, random_access_iterator<std::unique_ptr<int>*> >();
132     test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
133 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
134 }
135