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 / incl2.cpp < prev    next >
C/C++ Source or Header  |  2001-05-18  |  1KB  |  59 lines

  1. // STLport regression testsuite component.
  2. // To compile as a separate example, please #define MAIN.
  3.  
  4. #include <vector>
  5. #include <algorithm>
  6. #include <iostream>
  7. #include <cstring>
  8.  
  9. #ifdef MAIN 
  10. #define incl2_test main
  11. #endif
  12.  
  13. #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
  14. using namespace std;
  15. #endif
  16. static bool compare_strings(const char* s1_, const char* s2_)
  17. {
  18.   return strcmp(s1_, s2_) < 0 ? 1 : 0;
  19. }
  20. int incl2_test(int, char**)
  21. {
  22.   cout<<"Results of incl2_test:"<<endl;
  23.  
  24. char* names[] = {  "Todd", "Mike", "Graham", "Jack", "Brett"};
  25.  
  26.   const unsigned nameSize = sizeof(names)/sizeof(names[0]);
  27.   vector <char*> v1(nameSize);
  28.   for(int i = 0; i < v1.size(); i++)
  29.   {
  30.     v1[i] = names[i];
  31.   }
  32.   vector <char*> v2(2);
  33.  
  34.   v2[0] = "foo";
  35.   v2[1] = "bar";
  36.   sort(v1.begin(), v1.end(), compare_strings);
  37. //  cout << "v1 sorted;\n";
  38.   sort(v2.begin(), v2.end(), compare_strings);
  39. //  cout << "v1 sorted;\n";
  40.  
  41.   bool inc = includes(v1.begin(), v1.end(),
  42.                        v2.begin(), v2.end(),
  43.                        compare_strings);
  44.   if(inc)
  45.     cout << "v1 includes v2" << endl;
  46.   else
  47.     cout << "v1 does not include v2" << endl;
  48.   v2[0] = "Brett";
  49.   v2[1] = "Todd";
  50.   inc = includes(v1.begin(), v1.end(),
  51.                   v2.begin(), v2.end(),
  52.                   compare_strings);
  53.   if(inc)
  54.     cout << "v1 includes v2" << endl;
  55.   else
  56.     cout << "v1 does not include v2" << endl;
  57.   return 0;
  58. }
  59.