OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [tests/] [bvt14.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the uSTL library, an STL implementation.
2
//
3
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
 
6
#include "stdtest.h"
7
 
8
void TestMap (void)
9
{
10
    typedef map<string,int> monthmap_t;
11
    monthmap_t months;
12
    months["january"] = 31;
13
    months["february"] = 28;
14
    months["march"] = 31;
15
    months["april"] = 30;
16
    months["may"] = 31;
17
    months["june"] = 30;
18
    months["july"] = 31;
19
    months["august"] = 31;
20
    months["september"] = 30;
21
    months["october"] = 31;
22
    months["november"] = 30;
23
    months["december"] = 31;
24
 
25
    const monthmap_t& cmonths = months;
26
    cout << "There are " << cmonths["january"] << " days in january." << endl;
27
    cout << "There are " << cmonths["september"] << " days in september." << endl;
28
    cout << "There are " << cmonths["december"] << " days in december." << endl;
29
    monthmap_t::const_iterator found_may = months.find ("may");
30
    cout << found_may->first << " found at index " << found_may - months.begin() << endl;
31
    cout << "Alphabetical listing:" << endl;
32
 
33
    monthmap_t::const_iterator i;
34
    for (i = months.begin(); i < months.end(); ++ i)
35
        cout << i->first << " has " << i->second << " days." << endl;
36
 
37
    monthmap_t mcopy (months);
38
    mcopy.erase ("may");
39
    cout << "After erasing may:" << endl;
40
    for (i = mcopy.begin(); i < mcopy.end(); ++ i)
41
        cout << i->first << " ";
42
    cout << endl;
43
 
44
    mcopy.assign (months.begin(), months.end() - 1);
45
    mcopy.erase (mcopy.begin() + 1, mcopy.begin() + 4);
46
    cout << "After erasing months 2, 3, 4, and the last one:" << endl;
47
    for (i = mcopy.begin(); i < mcopy.end(); ++ i)
48
        cout << i->first << " ";
49
    cout << endl;
50
 
51
    mcopy = months;
52
    monthmap_t::iterator frob = mcopy.insert (make_pair (string("frobuary"), 42)).first;
53
    cout << "After inserting " << frob->first << "," << frob->second << ":" << endl;
54
    for (i = mcopy.begin(); i < mcopy.end(); ++ i)
55
        cout << i->first << " ";
56
    cout << endl;
57
}
58
 
59
StdBvtMain (TestMap)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.