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

  1. // STLport regression testsuite component.
  2. // To compile as a separate example, please #define MAIN.
  3. #include <iterator>
  4.  
  5. #include <algorithm>
  6. #include <vector>
  7. #include <iostream>
  8. #include <iterator>
  9. // #include <functional>
  10. #include <numeric>
  11.  
  12. #ifdef MAIN 
  13. #define search1_test main
  14. #endif
  15.  
  16. #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
  17. using namespace std;
  18. #endif
  19. int search1_test(int, char**)
  20. {
  21.   cout<<"Results of search1_test:"<<endl;
  22.   typedef vector <int> IntVec;
  23.   IntVec v1(10);
  24.   iota(v1.begin(), v1.end(), 0);
  25.   IntVec v2(3);
  26.   iota(v2.begin(), v2.end(), 50);
  27.   ostream_iterator <int> iter(cout, " ");
  28.  
  29.   cout << "v1: ";
  30.   copy(v1.begin(), v1.end(), iter);
  31.   cout << endl;
  32.   cout << "v2: ";
  33.   copy(v2.begin(), v2.end(), iter);
  34.   cout << endl;
  35.  
  36.   IntVec::iterator location;
  37.   location = search(v1.begin(), v1.end(), v2.begin(), v2.end());
  38.  
  39.   if(location == v1.end())
  40.     cout << "v2 not contained in v1" << endl;
  41.   else
  42.     cout << "Found v2 in v1 at offset: " << location - v1.begin() << endl;
  43.  
  44.   iota(v2.begin(), v2.end(), 4);
  45.   cout << "v1: ";
  46.   copy(v1.begin(), v1.end(), iter);
  47.   cout << endl;
  48.   cout << "v2: ";
  49.   copy(v2.begin(), v2.end(), iter);
  50.   cout << endl;
  51.  
  52.   location = search(v1.begin(), v1.end(), v2.begin(), v2.end());
  53.  
  54.   if(location == v1.end())
  55.     cout << "v2 not contained in v1" << endl;
  56.   else
  57.     cout << "Found v2 in v1 at offset: " << location - v1.begin() << endl;
  58.  
  59.   return 0;
  60. }
  61.