stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_hmap/src/hmmap1.cpp
changeset 0 e4d67989cc36
child 18 47c74d1534e1
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 
       
     2  
       
     3 // STLport regression testsuite component.
       
     4 // To compile as a separate example, please #define MAIN.
       
     5 
       
     6 #include <iostream>
       
     7 #include <hash_map>
       
     8 #include <rope>
       
     9 
       
    10 #ifdef MAIN
       
    11 #define hmmap1_test main
       
    12 #endif
       
    13 
       
    14 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    15 using namespace std;
       
    16 #endif
       
    17 
       
    18 //struct hash<string>
       
    19 //{
       
    20 //  size_t operator()(const string& s) const { return __stl_hash_string(s.c_str()); }
       
    21 //};
       
    22 
       
    23 // typedef _Hashtable_node< pair< const char, int > >* nodeptr;
       
    24 // __STL_TYPE_TRAITS_POD_SPECIALIZE(nodeptr);
       
    25 
       
    26 
       
    27 int hmmap1_test(int, char**)
       
    28 {
       
    29 	cout<<"Results of hmmap1_test:"<<endl;
       
    30 	typedef hash_multimap<char, int, hash<char>,equal_to<char> > mmap;
       
    31 	mmap m;
       
    32 	int failures = 0;
       
    33 	cout << "count('X') = " << m.count('X') << endl;
       
    34 	if(m.count('X') != 0)
       
    35 		failures++;
       
    36 
       
    37 	m.insert(pair<const char,int>('X', 10)); // Standard way.
       
    38 	cout << "count('X') = " << m.count('X') << endl;
       
    39 	if(m.count('X') != 1)
       
    40 		failures++;
       
    41 
       
    42 	//  m.insert('X', 20); // Non-standard, but very convenient!
       
    43 	m.insert(pair<const char,int>('X', 20));	// jbuck: standard way
       
    44 	cout << "count('X') = " << m.count('X') << endl;
       
    45 	if(m.count('X') != 2)
       
    46 		failures++;
       
    47 
       
    48 	//  m.insert('Y', 32);
       
    49 	m.insert(pair<const char,int>('Y', 32));	// jbuck: standard way
       
    50 	mmap::iterator i = m.find('X'); // Find first match.
       
    51 	while(i != m.end()) // Loop until end is reached.
       
    52 	{
       
    53 		cout <<(*i).first << " -> " <<(*i).second << endl;
       
    54 		i++;
       
    55 	}
       
    56 	int count = m.erase('X');
       
    57 	cout << "Erased " << count << " items" << endl;
       
    58 	if (count != 2)
       
    59 		failures++;
       
    60 
       
    61 	if (!failures)
       
    62 	return 0;
       
    63 	else
       
    64 	return 1;
       
    65 }