home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / test / regression / binsrch2.cpp < prev    next >
C/C++ Source or Header  |  2001-05-18  |  859b  |  34 lines

  1. // STLport regression testsuite component.
  2. // To compile as a separate example, please #define MAIN.
  3.  
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <cstring>
  7.  
  8. #ifdef MAIN 
  9. #define binsrch2_test main
  10. #endif
  11.  
  12. #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
  13. using namespace std;
  14. #endif
  15. static bool str_compare(const char* a_, const char* b_)
  16. {
  17.   return strcmp(a_, b_) < 0 ? 1 : 0;
  18. }
  19. int binsrch2_test(int, char**)
  20. {
  21.   cout<<"Results of binsrch2_test:"<<endl;
  22.  
  23. char* labels[] = { "aa", "dd", "ff", "jj", "ss", "zz" };
  24.  
  25.   const unsigned count = sizeof(labels) / sizeof(labels[0]);
  26.   // DEC C++ generates incorrect template instatiation code 
  27.   // for "ff" so must cast 
  28.   if(binary_search(labels, labels + count, (const char *)"ff", str_compare))
  29.     cout << "ff is in labels." << endl;
  30.   else
  31.     cout << "ff is not in labels." << endl;
  32.   return 0;
  33. }
  34.