1 // This file is part of the ustl library, an STL implementation.
3 // Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
11 typedef map
<string
,int> monthmap_t
;
13 months
["january"] = 31;
14 months
["february"] = 28;
20 months
["august"] = 31;
21 months
["september"] = 30;
22 months
["october"] = 31;
23 months
["november"] = 30;
24 months
["december"] = 31;
26 const monthmap_t
& cmonths
= months
;
27 cout
<< "There are " << cmonths
["january"] << " days in january." << endl
;
28 cout
<< "There are " << cmonths
["september"] << " days in september." << endl
;
29 cout
<< "There are " << cmonths
["december"] << " days in december." << endl
;
30 monthmap_t::const_iterator found_may
= months
.find ("may");
31 cout
<< found_may
->first
<< " found at index " << found_may
- months
.begin() << endl
;
32 cout
<< "Alphabetical listing:" << endl
;
34 monthmap_t::const_iterator i
;
35 for (i
= months
.begin(); i
< months
.end(); ++ i
)
36 cout
<< i
->first
<< " has " << i
->second
<< " days." << endl
;
38 monthmap_t
mcopy (months
);
40 cout
<< "After erasing may:" << endl
;
41 for (i
= mcopy
.begin(); i
< mcopy
.end(); ++ i
)
42 cout
<< i
->first
<< " ";
45 mcopy
.assign (months
.begin(), months
.end() - 1);
46 mcopy
.erase (mcopy
.begin() + 1, mcopy
.begin() + 4);
47 cout
<< "After erasing months 2, 3, 4, and the last one:" << endl
;
48 for (i
= mcopy
.begin(); i
< mcopy
.end(); ++ i
)
49 cout
<< i
->first
<< " ";
53 monthmap_t::iterator frob
= mcopy
.insert (make_pair (string("frobuary"), 42));
54 cout
<< "After inserting " << frob
->first
<< "," << frob
->second
<< ":" << endl
;
55 for (i
= mcopy
.begin(); i
< mcopy
.end(); ++ i
)
56 cout
<< i
->first
<< " ";