home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stl2vac.zip / STLport-4_5_3.zip / STLport-4.5.3 / test / regression / hmmap1.cpp < prev    next >
C/C++ Source or Header  |  2000-12-07  |  1KB  |  47 lines

  1. // STLport regression testsuite component.
  2. // To compile as a separate example, please #define MAIN.
  3.  
  4. #include <hash_map>
  5. #include <iostream>
  6.  
  7. #ifdef MAIN 
  8. #define hmmap1_test main
  9. #endif
  10.  
  11. #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
  12. using namespace std;
  13. #endif
  14.  
  15. //struct hash<string>
  16. //{
  17. //  size_t operator()(const string& s) const { return __stl_hash_string(s.c_str()); }
  18. //};
  19.  
  20. // typedef _Hashtable_node< pair< const char, int > >* nodeptr;
  21. // __STL_TYPE_TRAITS_POD_SPECIALIZE(nodeptr);
  22.  
  23.  
  24. int hmmap1_test(int, char**)
  25. {
  26.   cout<<"Results of hmmap1_test:"<<endl;
  27.   typedef hash_multimap<char, int, hash<char>,equal_to<char> > mmap;
  28.   mmap m;
  29.   cout << "count('X') = " << m.count('X') << endl;
  30.   m.insert(pair<const char,int>('X', 10)); // Standard way.
  31.   cout << "count('X') = " << m.count('X') << endl;
  32. //  m.insert('X', 20); // Non-standard, but very convenient!
  33.   m.insert(pair<const char,int>('X', 20));    // jbuck: standard way
  34.   cout << "count('X') = " << m.count('X') << endl;
  35. //  m.insert('Y', 32);
  36.   m.insert(pair<const char,int>('Y', 32));    // jbuck: standard way
  37.   mmap::iterator i = m.find('X'); // Find first match.
  38.   while(i != m.end()) // Loop until end is reached.
  39.   {
  40.     cout <<(*i).first << " -> " <<(*i).second << endl;
  41.     i++;
  42.   }
  43.   int count = m.erase('X');
  44.   cout << "Erased " << count << " items" << endl;
  45.   return 0;
  46. }
  47.