++


find_if()


template< class InputIterator, class Predicate >

InputIterator

find_if( InputIterator first,

InputIterator last, Predicate pred );

[first,last) pred. true, . find_if() InputIterator, ; last.

#include <algorithm>

#include <list>

#include <set>

#include <string>

#include <iostream.h>

//

// true, - FriendSet

class OurFriends { //

public:

bool operator()( const string& str ) {

return ( friendset.count( str ));

}

static void

FriendSet( const string *fs, int count ) {

copy( fs, fs+count,

inserter( friendset, friendset.end() ));

}

private:

static set< string, less<string>, allocator > friendset;

};

set< string, less<string>, allocator > OurFriends::friendset;

 

int main()

{

string Pooh_friends[] = { "", "", "-" };

string more_friends[] = { "", "", "" };

list<string,allocator> lf( more_friends, more_friends+3 );

 

//

OurFriends::FriendSet( Pooh_friends, 3 );

list<string,allocator>::iterator our_mutual_friend;

our_mutual_friend =

find_if( lf.begin(), lf.end(), OurFriends());

// :

// -, - .

if ( our_mutual_friend != lf.end() )

cout << "-, "

<< *our_mutual_friend

<< " .\n";

return 0;

}




- -  - -  - -