31
|
1 |
|
|
2 |
|
|
3 |
// STLport regression testsuite component.
|
|
4 |
// To compile as a separate example, please #define MAIN.
|
|
5 |
|
|
6 |
#include <vector>
|
|
7 |
#include <algorithm>
|
|
8 |
#include <iostream>
|
|
9 |
|
|
10 |
#ifdef MAIN
|
|
11 |
#define findif1_test main
|
|
12 |
#endif
|
|
13 |
|
|
14 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
15 |
using namespace std;
|
|
16 |
#endif
|
|
17 |
static bool div_3(int a_)
|
|
18 |
{
|
|
19 |
return a_ % 3 ? 0 : 1;
|
|
20 |
}
|
|
21 |
int findif1_test(int, char**)
|
|
22 |
{
|
|
23 |
cout<<"Results of findif1_test:"<<endl;
|
|
24 |
|
|
25 |
typedef vector <int> IntVec;
|
|
26 |
IntVec v(10);
|
|
27 |
for(int i = 0; i < v.size(); i++)
|
|
28 |
v[i] =(i + 1) *(i + 1);
|
|
29 |
IntVec::iterator iter;
|
|
30 |
iter = find_if(v.begin(), v.end(), div_3);
|
|
31 |
if(iter != v.end())
|
|
32 |
cout
|
|
33 |
<< "Value "
|
|
34 |
<< *iter
|
|
35 |
<< " at offset "
|
|
36 |
<<(iter - v.begin())
|
|
37 |
<< " is divisible by 3"
|
|
38 |
<< endl;
|
|
39 |
|
|
40 |
if((*iter == 9) && ((iter - v.begin()) == 2))
|
|
41 |
return 0;
|
|
42 |
else
|
|
43 |
return 1;
|
|
44 |
}
|