31
|
1 |
|
|
2 |
|
|
3 |
// STLport regression testsuite component.
|
|
4 |
// To compile as a separate example, please #define MAIN.
|
|
5 |
|
|
6 |
#include <string>
|
|
7 |
#include <vector>
|
|
8 |
#include <algorithm>
|
|
9 |
#include <iostream>
|
|
10 |
|
|
11 |
#ifdef MAIN
|
|
12 |
#define adjfind2_test main
|
|
13 |
#endif
|
|
14 |
|
|
15 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
16 |
using namespace std;
|
|
17 |
#endif
|
|
18 |
static int equal_length(const char* v1_, const char* v2_)
|
|
19 |
{
|
|
20 |
return ::strlen(v1_) == ::strlen(v2_);
|
|
21 |
}
|
|
22 |
int adjfind2_test(int, char**)
|
|
23 |
{
|
|
24 |
|
|
25 |
cout<<"Results of adjfind2_test:"<<endl;
|
|
26 |
typedef vector <char*> CStrVector;
|
|
27 |
|
|
28 |
char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" };
|
|
29 |
|
|
30 |
int failures =0;
|
|
31 |
const int nameCount = sizeof(names)/sizeof(names[0]);
|
|
32 |
CStrVector v(nameCount);
|
|
33 |
for(int i = 0; i < nameCount; i++)
|
|
34 |
v[i] = names[i];
|
|
35 |
CStrVector::iterator location;
|
|
36 |
location = adjacent_find(v.begin(), v.end(), equal_length);
|
|
37 |
if(location != v.end())
|
|
38 |
{
|
|
39 |
cout
|
|
40 |
<< "Found two adjacent strings of equal length: "
|
|
41 |
<< *location
|
|
42 |
<< " -and- "
|
|
43 |
<< *(location + 1)
|
|
44 |
<< endl;
|
|
45 |
//first matching pair should be found at location 2
|
|
46 |
if (*location != names[2])
|
|
47 |
failures++;
|
|
48 |
}
|
|
49 |
else
|
|
50 |
{
|
|
51 |
cout << "Didn't find two adjacent strings of equal length.";
|
|
52 |
failures++;
|
|
53 |
}
|
|
54 |
|
|
55 |
if (!failures)
|
|
56 |
return 0;
|
|
57 |
else
|
|
58 |
return 1;
|
|
59 |
}
|