stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_hmap/src/hmap1.cpp
changeset 0 e4d67989cc36
child 18 47c74d1534e1
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1  
       
     2 // STLport regression testsuite component.
       
     3 // To compile as a separate example, please #define MAIN.
       
     4 
       
     5 #include <iostream>
       
     6 #include <hash_map>
       
     7 #include <rope>
       
     8 
       
     9 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    10 using namespace std;
       
    11 #endif
       
    12 #ifdef MAIN
       
    13 #define hmap1_test main
       
    14 #endif
       
    15 
       
    16 int hmap1_test(int, char**)
       
    17 {
       
    18 	cout<<"Results of hmap1_test:"<<endl;
       
    19 	typedef hash_map<char, crope, hash<char>, equal_to<char> > maptype;
       
    20 	maptype m;
       
    21 
       
    22 	int failures = 0;
       
    23 	// Store mappings between roman numerals and decimals.
       
    24 	m['l'] = "50";
       
    25 	m['x'] = "20"; // Deliberate mistake.
       
    26 	m['v'] = "5";
       
    27 	m['i'] = "1";
       
    28 	cout << "m['x'] = " << m['x'] << endl;
       
    29 	
       
    30 	m['x'] = "10"; // Correct mistake.
       
    31 	cout << "m['x'] = " << m['x'] << endl;
       
    32 
       
    33 	cout << "m['z'] = " << m['z'] << endl; // Note default value is added.
       
    34 	cout << "m.count('z') = " << m.count('z') << endl;
       
    35 	
       
    36 	pair<maptype::iterator, bool> p =
       
    37 	m.insert(pair<const char, crope>('c', crope("100")));
       
    38 	if(p.second)
       
    39 	{
       
    40 		cout << "First insertion successful" << endl;
       
    41 	}
       
    42 	else
       
    43 	{
       
    44 		failures++;
       
    45 	}
       
    46 	p = m.insert(pair<const char, crope>('c', crope("100")));
       
    47 	if(p.second)
       
    48 	{
       
    49 		cout << "Second insertion successful" << endl;
       
    50 		failures++;
       
    51 	}
       
    52 	else
       
    53 	{
       
    54 		cout << "Existing pair " <<(*(p.first)).first
       
    55 		<< " -> " <<(*(p.first)).second << endl;		
       
    56 	}
       
    57 
       
    58 	if (!failures)
       
    59 	return 0;
       
    60 	else
       
    61 	return 1;
       
    62 }