// 以下是 wrong.cpp。那里出问题了?难道是 c++ 中的 find_end() 有 BUG?
#include
#include
#include
bool equals ( int elem1, int elem2 )
{
return 2 * elem1 == elem2;
}
int main(int argc,char *argv] )
{
using namespace std;
vector v1, v2;
vector ::iterator Iter1, Iter2;
int i;
for ( i = 0 ; i <= 5 ; i++ )
{
v2.push_back( 5 * i );
}
int iii;
for ( iii = 0 ; iii <= 11 ; iii++ )
{
v1.push_back(iii);
}
cout << "Vector v1 = ( " ;
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
cout << *Iter1 << " ";
cout << “)” << endl;
cout << "Vector v2 = ( " ;
for ( Iter2 = v2.begin( ) ; Iter2 != v2.end( ) ; Iter2++ )
cout << *Iter2 << " ";
cout << “)” << endl;
vector ::iterator result;
result = find_end ( v1.begin( ), v1.end( ), v2.begin( ), v2.end( ), equals );;
if ( result == v1.end( ) )
cout << “There is no match of v2 in v1.”
<< endl;
else
cout << "There is a sequence of elements in v1 that "
<< "are equivalent to those
in v2 under the binary "
<< "predicate twice and that begins at position "
<< result - v1.begin( ) << “.” <<endl;
}
/*
suse@linux-qmfx:~/program> g++ -o wrong up.cpp
suse@linux-qmfx:~/program> ./wrong
Vector v1 = ( 0 1 2 3 4 5 6 7 8 9 10 11 )
Vector v2 = ( 0 5 10 15 20 25 )
There is no match of v2 in v1.
suse@linux-qmfx:~/program>
#v1 中的 10 、5 为什么找不出来?
*/