home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stl453up.zip / stl453fx / test / regression / map1.cpp < prev    next >
C/C++ Source or Header  |  2002-04-29  |  1KB  |  46 lines

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