The Wayback Machine - https://web.archive.org/web/20180601205327/http://ja.cppreference.com:80/w/cpp/algorithm/is_partitioned
名前空間
変種
操作

std::is_partitioned

提供: cppreference.com
< cpp‎ | algorithm
 
 
アルゴリズムライブラリ
実行ポリシー (C++17)
非変更シーケンス操作
(C++11)(C++11)(C++11)
(C++17)
変更シーケンス操作
未初期化記憶域の操作
分割操作
is_partitioned
(C++11)
ソート操作
バイナリサーチ操作
集合操作 (ソート済み範囲用)
ヒープ操作
(C++11)
最小/最大演算
(C++11)
(C++17)
順列
数値演算
C のライブラリ
 
ヘッダ <algorithm> で定義
(1)
template<class InputIt, class UnaryPredicate >
bool is_partitioned( InputIt first, InputIt last, UnaryPredicate p );
(C++11およびそれ以降)
(C++20以前)
template<class InputIt, class UnaryPredicate >
constexprbool is_partitioned( InputIt first, InputIt last, UnaryPredicate p );
(C++20およびそれ以降)
template<class ExecutionPolicy, class ForwardIt, class UnaryPredicate >
bool is_partitioned( ExecutionPolicy&& policy, ForwardIt first, ForwardIt last, UnaryPredicate p );
(2) (C++17およびそれ以降)
1) 範囲 [first, last) 内の述語 p を満たすすべての要素が満たさないすべての要素より前に現れる場合は true を返します。 [first, last) が空の場合も true を返します。
2)(1) と同じですが、 policy に従って実行されます。 このオーバーロードは、 std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> が true である場合にのみ、オーバーロード解決に参加します

目次

[編集]引数

first, last - 調べる要素の範囲
policy - 使用する実行ポリシー。 詳細は実行ポリシーを参照してください
p - 範囲の先頭に見つかることが期待される要素に対して ​true を返す単項述語。

述語関数のシグネチャは以下と同等なものであるべきです。

 bool pred(const Type &a);

シグネチャが const& を持つ必要はありませんが、関数は渡されたオブジェクトを変更してはなりません。
TypeInputIt 型のオブジェクトの逆参照から暗黙に変換可能なものでなければなりません。 ​

型の要件
-
InputItInputIterator の要件を満たさなければなりません。
-
ForwardItForwardIterator の要件を満たさなければなりません。 また、その値型が UnaryPredicate's の引数型に変換可能でなければなりません。
-
UnaryPredicatePredicate の要件を満たさなければなりません。

[編集]戻り値

範囲 [first, last) が空または p によって分割されている場合は true、そうでなければ false

[編集]計算量

多くとも std::distance(first, last) 回の p の適用。

[編集]例外

テンプレート引数 ExecutionPolicy を持つオーバーロードは以下のようにエラーを報告します。

  • アルゴリズムの一部として呼び出された関数の実行が例外を投げ、 ExecutionPolicy が3つの標準のポリシーのいずれかの場合は、 std::terminate が呼ばれます。 それ以外のあらゆる ExecutionPolicy については、動作は処理系定義です。
  • アルゴリズムがメモリの確保に失敗した場合は、 std::bad_alloc が投げられます。

[編集]実装例

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))returnfalse;returntrue;}

[編集]

#include <algorithm>#include <array>#include <iostream>   int main(){std::array<int, 9> v ={1, 2, 3, 4, 5, 6, 7, 8, 9};   auto is_even =[](int i){return i %2==0;};std::cout.setf(std::ios_base::boolalpha);std::cout<< std::is_partitioned(v.begin(), v.end(), is_even)<<' ';   std::partition(v.begin(), v.end(), is_even);std::cout<< std::is_partitioned(v.begin(), v.end(), is_even)<<' ';   std::reverse(v.begin(), v.end());std::cout<< std::is_partitioned(v.begin(), v.end(), is_even);}

出力:

false true false

[編集]関連項目

指定範囲の要素を2つのグループに分割します
(関数テンプレート)[edit]
分割された範囲の分割点を探します
(関数テンプレート)[edit]
close