|
2904
|
1 // This file is part of the uSTL library, an STL implementation. |
|
|
2 // |
|
3152
|
3 // Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net> |
|
2904
|
4 // This file is free software, distributed under the MIT License. |
|
|
5 |
|
|
6 #include "stdtest.h" |
|
|
7 |
|
|
8 typedef multimap<int,string> empmap_t; |
|
|
9 typedef empmap_t::const_iterator citer_t; |
|
|
10 |
|
|
11 void PrintEntries (citer_t first, citer_t last) |
|
|
12 { |
|
|
13 for (citer_t i = first; i < last; ++ i) |
|
|
14 cout << i->second << "\t- $" << i->first << endl; |
|
|
15 } |
|
|
16 |
|
|
17 inline void PrintEntries (const empmap_t& m) { PrintEntries (m.begin(), m.end()); } |
|
|
18 |
|
|
19 void TestMultiMap (void) |
|
|
20 { |
|
|
21 empmap_t employees; |
|
|
22 employees.insert (make_pair (27000, string("Dave"))); |
|
|
23 employees.insert (make_pair (27000, string("Jim"))); |
|
|
24 employees.insert (make_pair (99000, string("BigBoss"))); |
|
|
25 employees.insert (make_pair (47000, string("Gail"))); |
|
|
26 employees.insert (make_pair (15000, string("Dumb"))); |
|
|
27 employees.insert (make_pair (47000, string("Barbara"))); |
|
|
28 employees.insert (make_pair (47000, string("Mary"))); |
|
|
29 |
|
3152
|
30 cout << "As-inserted listing:\n"; |
|
2904
|
31 PrintEntries (employees); |
|
|
32 |
|
3152
|
33 cout << "Alphabetical listing:\n"; |
|
2904
|
34 sort (employees); |
|
|
35 PrintEntries (employees); |
|
|
36 |
|
|
37 empmap_t::range_t middles = employees.equal_range (47000); |
|
|
38 cout << "Employees making $" << middles.first->first << ":"; |
|
|
39 empmap_t::const_iterator i; |
|
|
40 for (i = middles.first; i < middles.second; ++ i) |
|
|
41 cout << " " << i->second; |
|
|
42 cout << endl; |
|
|
43 |
|
3152
|
44 cout << employees.find(27000)->second << " makes $27000\n"; |
|
2904
|
45 |
|
3152
|
46 cout << "There are " << employees.count (27000) << " low-paid employees\n"; |
|
|
47 |
|
|
48 cout << "Firing all low-paid employees:\n"; |
|
2904
|
49 employees.erase (27000); |
|
|
50 PrintEntries (employees); |
|
|
51 |
|
3152
|
52 cout << "Firing dumb employees:\n"; |
|
2904
|
53 employees.erase (employees.begin(), employees.begin() + 1); |
|
|
54 PrintEntries (employees); |
|
|
55 } |
|
|
56 |
|
|
57 StdBvtMain (TestMultiMap) |