template<class InputIterator, class BinaryPredicate>
bool is_partitioned(
InputIterator _First,
InputIterator _Last,
BinaryPredicate _Comp
);
template<class ForwardIterator, class Predicate>
ForwardIterator partition_point(
ForwardIterator _First,
ForwardIterator _Last,
Predicate _Comp
);
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;
struct PLAYER
{
int CharCD;
bool IsRedTeam;
};
int main()
{
vector< PLAYER > StagePlayers1;
PLAYER player1; player1.CharCD = 1; player1.IsRedTeam = true; StagePlayers1.push_back( player1 );
PLAYER player2; player2.CharCD = 2; player2.IsRedTeam = true; StagePlayers1.push_back( player2 );
PLAYER player3; player3.CharCD = 3; player3.IsRedTeam = true; StagePlayers1.push_back( player3 );
PLAYER player4; player4.CharCD = 4; player4.IsRedTeam = false; StagePlayers1.push_back( player4 );
PLAYER player5; player5.CharCD = 5; player5.IsRedTeam = false; StagePlayers1.push_back( player5 );
PLAYER player6; player6.CharCD = 6; player6.IsRedTeam = false; StagePlayers1.push_back( player6 );
PLAYER player7; player7.CharCD = 7; player7.IsRedTeam = false; StagePlayers1.push_back( player7 );
bool IsPartitioned = is_partitioned( StagePlayers1.begin(), StagePlayers1.end(),
[]( PLAYER player ) -> bool { return player.IsRedTeam; } );
if( IsPartitioned ) {
cout << "레드 팀과 블루 팀으로 구분 되어 나누어져 있습니다." << endl;
} else {
cout << "레드 팀과 블루 팀으로 구분 되어 있지 않습니다." << endl;
}
vector< PLAYER >::iterator IterFirstBlueTeamPlayer = partition_point( StagePlayers1.begin(),StagePlayers1.end(),
[]( PLAYER player ) -> bool { return player.IsRedTeam; } );
if( IterFirstBlueTeamPlayer != StagePlayers1.end() ) {
cout << "첫 번째 블루 팀 플레이어. 캐릭터 코드 : " << (*IterFirstBlueTeamPlayer).CharCD << endl;
}
vector< PLAYER > StagePlayers2;
StagePlayers2.push_back( player7 );
StagePlayers2.push_back( player6 );
StagePlayers2.push_back( player1 );
StagePlayers2.push_back( player5 );
StagePlayers2.push_back( player4 );
StagePlayers2.push_back( player3 );
StagePlayers2.push_back( player2 );
IsPartitioned = is_partitioned( StagePlayers2.begin(), StagePlayers2.end(),
[]( PLAYER player ) -> bool { return player.IsRedTeam; } );
if( IsPartitioned ) {
cout << "레드 팀과 블루 팀으로 구분 되어 나누어져 있습니다." << endl;
} else {
cout << "레드 팀과 블루 팀으로 구분 되어 있지 않습니다." << endl;
}
getchar();
return 0;
}