++


mismatch()


template< class InputIterator1, class InputIterator2 >

pair<InputIterator1, InputIterator2>

mismatch( InputIterator1 first,

InputIterator1 last, InputIterator2 first2 );

 

template< class InputIterator1, class InputIterator2,

class BinaryPredicate >

pair<InputIterator1, InputIterator2>

mismatch( InputIterator1 first, InputIterator1 last,

InputIterator2 first2, BinaryPredicate pred );

mismatch() , . , . , last . , meet meat, . ,   , . , ; , .

#include <algorithm>

#include <list>

#include <utility>

#include <iostream.h>

class equal_and_odd{

public:

bool operator()( int ival1, int ival2 )

{

// ?

// ? ?

return ( ival1 == ival2 &&

( ival1 == 0 || ival1%2 ));

}

};

int main()

{

int ia[] = { 0,1,1,2,3,5,8,13 };

int ia2[] = { 0,1,1,2,4,6,10 };

pair<int*,int*> pair_ia = mismatch( ia, ia+7, ia2 );

 

// : : ia: 3 ia2: 4

cout << " : ia: "

<< *pair_ia.first << " ia2: "

<< *pair_ia.second << endl;

list<int,allocator> ilist( ia, ia+7 );

list<int,allocator> ilist2( ia2, ia2+7 );

typedef list<int,allocator>::iterator iter;

pair<iter,iter> pair_ilist =

mismatch( ilist.begin(), ilist.end(),

ilist2.begin(), equal_and_odd() );

 

// : : , :

// ilist: 2 ilist2: 2

cout << " : , "

<< " : \n\tilist: "

<< *pair_ilist.first << " ilist2: "

<< *pair_ilist.second << endl;

}




- -  - -  - -