Cpp-standard-library-cpp-algorithm-is-partitioned
提供:Dev Guides
C ++アルゴリズムライブラリ-is_partitioned()関数
説明
- C ++関数* std
- algorithm :: is_partitioned()*は、範囲がパーティション化されているかどうかをテストします。 空の範囲の場合、この関数はtrueを返します。
宣言
- 以下は、std
- algorithmヘッダーからのstd :: algorithm :: is_partitioned()関数の宣言です。
C 11
template <class InputIterator, class UnaryPredicate>
bool is_partitioned (InputIterator first, InputIterator last, UnaryPredicate pred);
パラメーター
- first -イテレータを初期位置に入力します。
- last -最終位置に反復子を入力します。
- pred -要素を受け取り、ブール値を返す単項関数。
戻り値
範囲が分割されている場合はtrueを返し、そうでない場合はfalseを返します。
例外
`+ pred +`またはイテレータの操作が例外をスローした場合、例外をスローします。
無効なパラメータは未定義の動作を引き起こすことに注意してください。
時間の複雑さ
リニア。
例
- 次の例は、std
- algorithm :: is_partitioned()関数の使用法を示しています。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool is_even(int n) {
return (n % 2 == 0);
}
int main(void) {
vector<int> v = {1, 2, 3, 4, 5};
bool result;
result = is_partitioned(v.begin(), v.end(), is_even);
if (result == false)
cout << "Vector is not partitioned." << endl;
partition(v.begin(), v.end(), is_even);
result = is_partitioned(v.begin(), v.end(), is_even);
if (result == true)
cout << "Vector is paritioned." << endl;
return 0;
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
Vector is not partitioned.
Vector is paritioned.