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