31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// STLport regression testsuite component.
|
|
19 |
// To compile as a separate example, please #define MAIN.
|
|
20 |
|
|
21 |
#include <iostream>
|
|
22 |
#include <hash_map>
|
|
23 |
#include <rope>
|
|
24 |
|
|
25 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
26 |
using namespace std;
|
|
27 |
#endif
|
|
28 |
#ifdef MAIN
|
|
29 |
#define hmap1_test main
|
|
30 |
#endif
|
|
31 |
|
|
32 |
int hmap1_test(int, char**)
|
|
33 |
{
|
|
34 |
cout<<"Results of hmap1_test:"<<endl;
|
|
35 |
typedef hash_map<char, crope, hash<char>, equal_to<char> > maptype;
|
|
36 |
maptype m;
|
|
37 |
|
|
38 |
int failures = 0;
|
|
39 |
// Store mappings between roman numerals and decimals.
|
|
40 |
m['l'] = "50";
|
|
41 |
m['x'] = "20"; // Deliberate mistake.
|
|
42 |
m['v'] = "5";
|
|
43 |
m['i'] = "1";
|
|
44 |
cout << "m['x'] = " << m['x'] << endl;
|
|
45 |
|
|
46 |
m['x'] = "10"; // Correct mistake.
|
|
47 |
cout << "m['x'] = " << m['x'] << endl;
|
|
48 |
|
|
49 |
cout << "m['z'] = " << m['z'] << endl; // Note default value is added.
|
|
50 |
cout << "m.count('z') = " << m.count('z') << endl;
|
|
51 |
|
|
52 |
pair<maptype::iterator, bool> p =
|
|
53 |
m.insert(pair<const char, crope>('c', crope("100")));
|
|
54 |
if(p.second)
|
|
55 |
{
|
|
56 |
cout << "First insertion successful" << endl;
|
|
57 |
}
|
|
58 |
else
|
|
59 |
{
|
|
60 |
failures++;
|
|
61 |
}
|
|
62 |
p = m.insert(pair<const char, crope>('c', crope("100")));
|
|
63 |
if(p.second)
|
|
64 |
{
|
|
65 |
cout << "Second insertion successful" << endl;
|
|
66 |
failures++;
|
|
67 |
}
|
|
68 |
else
|
|
69 |
{
|
|
70 |
cout << "Existing pair " <<(*(p.first)).first
|
|
71 |
<< " -> " <<(*(p.first)).second << endl;
|
|
72 |
}
|
|
73 |
|
|
74 |
if (!failures)
|
|
75 |
return 0;
|
|
76 |
else
|
|
77 |
return 1;
|
|
78 |
}
|