is_partitioned

is_partitioned是一種用來判斷[first,last)區間內的所有元素是不是以函式P為準則的劃分。

函式描述,函式參數說明,返回值,函式內部執行,函式套用舉例,

函式描述

is_partitioned 函式存在於 <algorithm>
函式原型如下:
template< class InputIt, class UnaryPredicate >
bool is_partitioned( InputIt first, InputIt last, UnaryPredicate p );

函式參數說明

first, last - 要檢測的區間
p -檢測的標準函式,滿足該函式的返回true,否則返回false

返回值

如果[first,last)區間滿足以標準函式p為原則劃分,則返回true,否則false

函式內部執行

template<class InputIt, class UnaryPredicate >
bool is_partitioned(InputIt first, InputIt last, UnaryPredicate p)
{
for(; first != last;++first)
if(!p(*first))
break;
for(; first != last;++first)
if(p(*first))
return false;
return true;
}

函式套用舉例

#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<ctime>
#include<cstdlib>
using namespace std;
template<class T>
struct isEven
{
public:
bool operator() (const T& a)
{
return a%2==1;
}
};
int Rand(const int& a)
{
srand(time(NULL));
return rand()%a;
}
int main(int argc,char* argv[])
{

相關詞條

熱門詞條

聯絡我們