summaryrefslogtreecommitdiff
path: root/ecos/packages/language/cxx/ustl/current/tests/bvt15.cpp
blob: cf819bf566989b5bbeb6cc09ea69cdb4e4521af4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.

#include "stdtest.h"

typedef multimap<int,string> empmap_t;
typedef empmap_t::const_iterator citer_t;

void PrintEntries (citer_t first, citer_t last)
{
    for (citer_t i = first; i < last; ++ i)
	cout << i->second << "\t- $" << i->first << endl;
}

inline void PrintEntries (const empmap_t& m)	{ PrintEntries (m.begin(), m.end()); }

void TestMultiMap (void)
{
    empmap_t employees;
    employees.insert (make_pair (27000, string("Dave"))); 
    employees.insert (make_pair (27000, string("Jim"))); 
    employees.insert (make_pair (99000, string("BigBoss"))); 
    employees.insert (make_pair (47000, string("Gail"))); 
    employees.insert (make_pair (15000, string("Dumb"))); 
    employees.insert (make_pair (47000, string("Barbara"))); 
    employees.insert (make_pair (47000, string("Mary"))); 

    cout << "As-inserted listing:\n";
    PrintEntries (employees);

    cout << "Alphabetical listing:\n";
    sort (employees);
    PrintEntries (employees);

    empmap_t::range_t middles = employees.equal_range (47000);
    cout << "Employees making $" << middles.first->first << ":";
    empmap_t::const_iterator i;
    for (i = middles.first; i < middles.second; ++ i)
	cout << " " << i->second;
    cout << endl;

    cout << employees.find(27000)->second << " makes $27000\n";

    cout << "There are " << employees.count (27000) << " low-paid employees\n";

    cout << "Firing all low-paid employees:\n";
    employees.erase (27000);
    PrintEntries (employees);

    cout << "Firing dumb employees:\n";
    employees.erase (employees.begin(), employees.begin() + 1);
    PrintEntries (employees);
}

StdBvtMain (TestMultiMap)