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 // <map>
11
12 // class multimap
13
14 // iterator find(const key_type& k);
15 // const_iterator find(const key_type& k) const;
16
17 #include <map>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 #include "private_constructor.hpp"
23 #include "is_transparent.h"
24
main()25 int main()
26 {
27 typedef std::pair<const int, double> V;
28 {
29 typedef std::multimap<int, double> M;
30 {
31 typedef M::iterator R;
32 V ar[] =
33 {
34 V(5, 1),
35 V(5, 2),
36 V(5, 3),
37 V(7, 1),
38 V(7, 2),
39 V(7, 3),
40 V(9, 1),
41 V(9, 2),
42 V(9, 3)
43 };
44 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
45 R r = m.find(5);
46 assert(r == m.begin());
47 r = m.find(6);
48 assert(r == m.end());
49 r = m.find(7);
50 assert(r == next(m.begin(), 3));
51 r = m.find(8);
52 assert(r == m.end());
53 r = m.find(9);
54 assert(r == next(m.begin(), 6));
55 r = m.find(10);
56 assert(r == m.end());
57 }
58 {
59 typedef M::const_iterator R;
60 V ar[] =
61 {
62 V(5, 1),
63 V(5, 2),
64 V(5, 3),
65 V(7, 1),
66 V(7, 2),
67 V(7, 3),
68 V(9, 1),
69 V(9, 2),
70 V(9, 3)
71 };
72 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
73 R r = m.find(5);
74 assert(r == m.begin());
75 r = m.find(6);
76 assert(r == m.end());
77 r = m.find(7);
78 assert(r == next(m.begin(), 3));
79 r = m.find(8);
80 assert(r == m.end());
81 r = m.find(9);
82 assert(r == next(m.begin(), 6));
83 r = m.find(10);
84 assert(r == m.end());
85 }
86 }
87 #if TEST_STD_VER >= 11
88 {
89 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
90 {
91 typedef M::iterator R;
92 V ar[] =
93 {
94 V(5, 1),
95 V(5, 2),
96 V(5, 3),
97 V(7, 1),
98 V(7, 2),
99 V(7, 3),
100 V(9, 1),
101 V(9, 2),
102 V(9, 3)
103 };
104 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
105 R r = m.find(5);
106 assert(r == m.begin());
107 r = m.find(6);
108 assert(r == m.end());
109 r = m.find(7);
110 assert(r == next(m.begin(), 3));
111 r = m.find(8);
112 assert(r == m.end());
113 r = m.find(9);
114 assert(r == next(m.begin(), 6));
115 r = m.find(10);
116 assert(r == m.end());
117 }
118 {
119 typedef M::const_iterator R;
120 V ar[] =
121 {
122 V(5, 1),
123 V(5, 2),
124 V(5, 3),
125 V(7, 1),
126 V(7, 2),
127 V(7, 3),
128 V(9, 1),
129 V(9, 2),
130 V(9, 3)
131 };
132 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
133 R r = m.find(5);
134 assert(r == m.begin());
135 r = m.find(6);
136 assert(r == m.end());
137 r = m.find(7);
138 assert(r == next(m.begin(), 3));
139 r = m.find(8);
140 assert(r == m.end());
141 r = m.find(9);
142 assert(r == next(m.begin(), 6));
143 r = m.find(10);
144 assert(r == m.end());
145 }
146 }
147 #endif
148 #if TEST_STD_VER > 11
149 {
150 typedef std::multimap<int, double, std::less<>> M;
151 typedef M::iterator R;
152
153 V ar[] =
154 {
155 V(5, 1),
156 V(5, 2),
157 V(5, 3),
158 V(7, 1),
159 V(7, 2),
160 V(7, 3),
161 V(9, 1),
162 V(9, 2),
163 V(9, 3)
164 };
165 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
166 R r = m.find(5);
167 assert(r == m.begin());
168 r = m.find(6);
169 assert(r == m.end());
170 r = m.find(7);
171 assert(r == next(m.begin(), 3));
172 r = m.find(8);
173 assert(r == m.end());
174 r = m.find(9);
175 assert(r == next(m.begin(), 6));
176 r = m.find(10);
177 assert(r == m.end());
178
179 r = m.find(C2Int(5));
180 assert(r == m.begin());
181 r = m.find(C2Int(6));
182 assert(r == m.end());
183 r = m.find(C2Int(7));
184 assert(r == next(m.begin(), 3));
185 r = m.find(C2Int(8));
186 assert(r == m.end());
187 r = m.find(C2Int(9));
188 assert(r == next(m.begin(), 6));
189 r = m.find(C2Int(10));
190 assert(r == m.end());
191 }
192
193 {
194 typedef PrivateConstructor PC;
195 typedef std::multimap<PC, double, std::less<>> M;
196 typedef M::iterator R;
197
198 M m;
199 m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
200 m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
201 m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
202 m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
203 m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
204 m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
205 m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
206 m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
207 m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
208
209 R r = m.find(5);
210 assert(r == m.begin());
211 r = m.find(6);
212 assert(r == m.end());
213 r = m.find(7);
214 assert(r == next(m.begin(), 3));
215 r = m.find(8);
216 assert(r == m.end());
217 r = m.find(9);
218 assert(r == next(m.begin(), 6));
219 r = m.find(10);
220 assert(r == m.end());
221 }
222 #endif
223 }
224