home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / test / regression / findif1.cpp < prev    next >
C/C++ Source or Header  |  2000-12-07  |  777b  |  39 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.  
  8. #ifdef MAIN 
  9. #define findif1_test main
  10. #endif
  11.  
  12. #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
  13. using namespace std;
  14. #endif
  15. static bool div_3(int a_)
  16. {
  17.   return a_ % 3 ? 0 : 1;
  18. }
  19. int findif1_test(int, char**)
  20. {
  21.   cout<<"Results of findif1_test:"<<endl;
  22.  
  23.   typedef vector <int> IntVec;
  24.   IntVec v(10);
  25.   for(int i = 0; i < v.size(); i++)
  26.     v[i] =(i + 1) *(i + 1);
  27.   IntVec::iterator iter;
  28.   iter = find_if(v.begin(), v.end(), div_3);
  29.   if(iter != v.end())
  30.     cout
  31.       << "Value "
  32.       << *iter
  33.       << " at offset "
  34.       <<(iter - v.begin())
  35.       << " is divisible by 3"
  36.       << endl;
  37.   return 0;
  38. }
  39.