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

  1. #ifdef MAIN 
  2. #define hmap1_test main
  3. #endif
  4. // STLport regression testsuite component.
  5. // To compile as a separate example, please #define MAIN.
  6.  
  7. #include <iostream>
  8. #include <hash_map>
  9. #include <rope>
  10.  
  11. #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
  12. using namespace std;
  13. #endif
  14.  
  15. int hmap1_test(int, char**)
  16. {
  17.   cout<<"Results of hmap1_test:"<<endl;
  18.   typedef hash_map<char, crope, hash<char>, equal_to<char> > maptype;
  19.   maptype m;
  20.   // Store mappings between roman numerals and decimals.
  21.   m['l'] = "50";
  22.   m['x'] = "20"; // Deliberate mistake.
  23.   m['v'] = "5";
  24.   m['i'] = "1";
  25.   cout << "m['x'] = " << m['x'] << endl;
  26.   m['x'] = "10"; // Correct mistake.
  27.   cout << "m['x'] = " << m['x'] << endl;
  28.   cout << "m['z'] = " << m['z'] << endl; // Note default value is added.
  29.   cout << "m.count('z') = " << m.count('z') << endl;
  30.   pair<maptype::iterator, bool> p =
  31.       m.insert(pair<const char, crope>('c', crope("100")));
  32.   if(p.second)
  33.     cout << "First insertion successful" << endl;
  34.   p = m.insert(pair<const char, crope>('c', crope("100")));
  35.   if(p.second)
  36.     cout << "Second insertion successful" << endl;
  37.   else
  38.     cout << "Existing pair " <<(*(p.first)).first
  39.          << " -> " <<(*(p.first)).second << endl;
  40.   return 0;
  41. }
  42.