31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// STLport regression testsuite component.
|
|
20 |
// To compile as a separate example, please #define MAIN.
|
|
21 |
|
|
22 |
#include <vector>
|
|
23 |
#include <algorithm>
|
|
24 |
#include <iostream>
|
|
25 |
|
|
26 |
#ifdef MAIN
|
|
27 |
#define findif1_test main
|
|
28 |
#endif
|
|
29 |
|
|
30 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
31 |
using namespace std;
|
|
32 |
#endif
|
|
33 |
static bool div_3(int a_)
|
|
34 |
{
|
|
35 |
return a_ % 3 ? 0 : 1;
|
|
36 |
}
|
|
37 |
int findif1_test(int, char**)
|
|
38 |
{
|
|
39 |
cout<<"Results of findif1_test:"<<endl;
|
|
40 |
|
|
41 |
typedef vector <int> IntVec;
|
|
42 |
IntVec v(10);
|
|
43 |
for(int i = 0; i < v.size(); i++)
|
|
44 |
v[i] =(i + 1) *(i + 1);
|
|
45 |
IntVec::iterator iter;
|
|
46 |
iter = find_if(v.begin(), v.end(), div_3);
|
|
47 |
if(iter != v.end())
|
|
48 |
cout
|
|
49 |
<< "Value "
|
|
50 |
<< *iter
|
|
51 |
<< " at offset "
|
|
52 |
<<(iter - v.begin())
|
|
53 |
<< " is divisible by 3"
|
|
54 |
<< endl;
|
|
55 |
|
|
56 |
if((*iter == 9) && ((iter - v.begin()) == 2))
|
|
57 |
return 0;
|
|
58 |
else
|
|
59 |
return 1;
|
|
60 |
}
|