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