• 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 InIter1, InputIterator InIter2, class OutIter,
13 //          Callable<auto, const InIter1::value_type&, const InIter2::value_type&> BinaryOp>
14 //   requires OutputIterator<OutIter, BinaryOp::result_type> && CopyConstructible<BinaryOp>
15 // OutIter
16 // transform(InIter1 first1, InIter1 last1, InIter2 first2, OutIter result, BinaryOp binary_op);
17 
18 #include <algorithm>
19 #include <functional>
20 #include <cassert>
21 
22 #include "test_iterators.h"
23 
24 template<class InIter1, class InIter2, class OutIter>
25 void
test()26 test()
27 {
28     int ia[] = {0, 1, 2, 3, 4};
29     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
30     int ib[sa] = {1, 2, 3, 4, 5};
31     OutIter r = std::transform(InIter1(ib), InIter1(ib+sa), InIter2(ia),
32                                OutIter(ib), std::minus<int>());
33     assert(base(r) == ib + sa);
34     assert(ib[0] == 1);
35     assert(ib[1] == 1);
36     assert(ib[2] == 1);
37     assert(ib[3] == 1);
38     assert(ib[4] == 1);
39 }
40 
main()41 int main()
42 {
43     test<input_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
44     test<input_iterator<const int*>, input_iterator<const int*>, input_iterator<int*> >();
45     test<input_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
46     test<input_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
47     test<input_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
48     test<input_iterator<const int*>, input_iterator<const int*>, int*>();
49 
50     test<input_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
51     test<input_iterator<const int*>, forward_iterator<const int*>, input_iterator<int*> >();
52     test<input_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
53     test<input_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
54     test<input_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
55     test<input_iterator<const int*>, forward_iterator<const int*>, int*>();
56 
57     test<input_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
58     test<input_iterator<const int*>, bidirectional_iterator<const int*>, input_iterator<int*> >();
59     test<input_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
60     test<input_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
61     test<input_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
62     test<input_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
63 
64     test<input_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
65     test<input_iterator<const int*>, random_access_iterator<const int*>, input_iterator<int*> >();
66     test<input_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
67     test<input_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
68     test<input_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
69     test<input_iterator<const int*>, random_access_iterator<const int*>, int*>();
70 
71     test<input_iterator<const int*>, const int*, output_iterator<int*> >();
72     test<input_iterator<const int*>, const int*, input_iterator<int*> >();
73     test<input_iterator<const int*>, const int*, forward_iterator<int*> >();
74     test<input_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
75     test<input_iterator<const int*>, const int*, random_access_iterator<int*> >();
76     test<input_iterator<const int*>, const int*, int*>();
77 
78     test<forward_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
79     test<forward_iterator<const int*>, input_iterator<const int*>, input_iterator<int*> >();
80     test<forward_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
81     test<forward_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
82     test<forward_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
83     test<forward_iterator<const int*>, input_iterator<const int*>, int*>();
84 
85     test<forward_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
86     test<forward_iterator<const int*>, forward_iterator<const int*>, input_iterator<int*> >();
87     test<forward_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
88     test<forward_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
89     test<forward_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
90     test<forward_iterator<const int*>, forward_iterator<const int*>, int*>();
91 
92     test<forward_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
93     test<forward_iterator<const int*>, bidirectional_iterator<const int*>, input_iterator<int*> >();
94     test<forward_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
95     test<forward_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
96     test<forward_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
97     test<forward_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
98 
99     test<forward_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
100     test<forward_iterator<const int*>, random_access_iterator<const int*>, input_iterator<int*> >();
101     test<forward_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
102     test<forward_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
103     test<forward_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
104     test<forward_iterator<const int*>, random_access_iterator<const int*>, int*>();
105 
106     test<forward_iterator<const int*>, const int*, output_iterator<int*> >();
107     test<forward_iterator<const int*>, const int*, input_iterator<int*> >();
108     test<forward_iterator<const int*>, const int*, forward_iterator<int*> >();
109     test<forward_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
110     test<forward_iterator<const int*>, const int*, random_access_iterator<int*> >();
111     test<forward_iterator<const int*>, const int*, int*>();
112 
113     test<bidirectional_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
114     test<bidirectional_iterator<const int*>, input_iterator<const int*>, input_iterator<int*> >();
115     test<bidirectional_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
116     test<bidirectional_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
117     test<bidirectional_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
118     test<bidirectional_iterator<const int*>, input_iterator<const int*>, int*>();
119 
120     test<bidirectional_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
121     test<bidirectional_iterator<const int*>, forward_iterator<const int*>, input_iterator<int*> >();
122     test<bidirectional_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
123     test<bidirectional_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
124     test<bidirectional_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
125     test<bidirectional_iterator<const int*>, forward_iterator<const int*>, int*>();
126 
127     test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
128     test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, input_iterator<int*> >();
129     test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
130     test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
131     test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
132     test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
133 
134     test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
135     test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, input_iterator<int*> >();
136     test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
137     test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
138     test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
139     test<bidirectional_iterator<const int*>, random_access_iterator<const int*>, int*>();
140 
141     test<bidirectional_iterator<const int*>, const int*, output_iterator<int*> >();
142     test<bidirectional_iterator<const int*>, const int*, input_iterator<int*> >();
143     test<bidirectional_iterator<const int*>, const int*, forward_iterator<int*> >();
144     test<bidirectional_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
145     test<bidirectional_iterator<const int*>, const int*, random_access_iterator<int*> >();
146     test<bidirectional_iterator<const int*>, const int*, int*>();
147 
148     test<random_access_iterator<const int*>, input_iterator<const int*>, output_iterator<int*> >();
149     test<random_access_iterator<const int*>, input_iterator<const int*>, input_iterator<int*> >();
150     test<random_access_iterator<const int*>, input_iterator<const int*>, forward_iterator<int*> >();
151     test<random_access_iterator<const int*>, input_iterator<const int*>, bidirectional_iterator<int*> >();
152     test<random_access_iterator<const int*>, input_iterator<const int*>, random_access_iterator<int*> >();
153     test<random_access_iterator<const int*>, input_iterator<const int*>, int*>();
154 
155     test<random_access_iterator<const int*>, forward_iterator<const int*>, output_iterator<int*> >();
156     test<random_access_iterator<const int*>, forward_iterator<const int*>, input_iterator<int*> >();
157     test<random_access_iterator<const int*>, forward_iterator<const int*>, forward_iterator<int*> >();
158     test<random_access_iterator<const int*>, forward_iterator<const int*>, bidirectional_iterator<int*> >();
159     test<random_access_iterator<const int*>, forward_iterator<const int*>, random_access_iterator<int*> >();
160     test<random_access_iterator<const int*>, forward_iterator<const int*>, int*>();
161 
162     test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, output_iterator<int*> >();
163     test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, input_iterator<int*> >();
164     test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, forward_iterator<int*> >();
165     test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
166     test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
167     test<random_access_iterator<const int*>, bidirectional_iterator<const int*>, int*>();
168 
169     test<random_access_iterator<const int*>, random_access_iterator<const int*>, output_iterator<int*> >();
170     test<random_access_iterator<const int*>, random_access_iterator<const int*>, input_iterator<int*> >();
171     test<random_access_iterator<const int*>, random_access_iterator<const int*>, forward_iterator<int*> >();
172     test<random_access_iterator<const int*>, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
173     test<random_access_iterator<const int*>, random_access_iterator<const int*>, random_access_iterator<int*> >();
174     test<random_access_iterator<const int*>, random_access_iterator<const int*>, int*>();
175 
176     test<random_access_iterator<const int*>, const int*, output_iterator<int*> >();
177     test<random_access_iterator<const int*>, const int*, input_iterator<int*> >();
178     test<random_access_iterator<const int*>, const int*, forward_iterator<int*> >();
179     test<random_access_iterator<const int*>, const int*, bidirectional_iterator<int*> >();
180     test<random_access_iterator<const int*>, const int*, random_access_iterator<int*> >();
181     test<random_access_iterator<const int*>, const int*, int*>();
182 
183     test<const int*, input_iterator<const int*>, output_iterator<int*> >();
184     test<const int*, input_iterator<const int*>, input_iterator<int*> >();
185     test<const int*, input_iterator<const int*>, forward_iterator<int*> >();
186     test<const int*, input_iterator<const int*>, bidirectional_iterator<int*> >();
187     test<const int*, input_iterator<const int*>, random_access_iterator<int*> >();
188     test<const int*, input_iterator<const int*>, int*>();
189 
190     test<const int*, forward_iterator<const int*>, output_iterator<int*> >();
191     test<const int*, forward_iterator<const int*>, input_iterator<int*> >();
192     test<const int*, forward_iterator<const int*>, forward_iterator<int*> >();
193     test<const int*, forward_iterator<const int*>, bidirectional_iterator<int*> >();
194     test<const int*, forward_iterator<const int*>, random_access_iterator<int*> >();
195     test<const int*, forward_iterator<const int*>, int*>();
196 
197     test<const int*, bidirectional_iterator<const int*>, output_iterator<int*> >();
198     test<const int*, bidirectional_iterator<const int*>, input_iterator<int*> >();
199     test<const int*, bidirectional_iterator<const int*>, forward_iterator<int*> >();
200     test<const int*, bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
201     test<const int*, bidirectional_iterator<const int*>, random_access_iterator<int*> >();
202     test<const int*, bidirectional_iterator<const int*>, int*>();
203 
204     test<const int*, random_access_iterator<const int*>, output_iterator<int*> >();
205     test<const int*, random_access_iterator<const int*>, input_iterator<int*> >();
206     test<const int*, random_access_iterator<const int*>, forward_iterator<int*> >();
207     test<const int*, random_access_iterator<const int*>, bidirectional_iterator<int*> >();
208     test<const int*, random_access_iterator<const int*>, random_access_iterator<int*> >();
209     test<const int*, random_access_iterator<const int*>, int*>();
210 
211     test<const int*, const int*, output_iterator<int*> >();
212     test<const int*, const int*, input_iterator<int*> >();
213     test<const int*, const int*, forward_iterator<int*> >();
214     test<const int*, const int*, bidirectional_iterator<int*> >();
215     test<const int*, const int*, random_access_iterator<int*> >();
216     test<const int*, const int*, int*>();
217 }
218