次の方法で共有


stable_partition

2 の範囲の要素を送信します。を満たさない、前の単項演算子の述語を満たす。これらの要素がセットを使用して、同等の要素の相対位置ディレクティブを保持します。

template<class BidirectionalIterator, class Predicate>
   BidirectionalIterator stable_partition(
      BidirectionalIterator _First, 
      BidirectionalIterator _Last,
      Predicate _Pred
   );

パラメーター

  • _First
    仕切られるする範囲の先頭の要素の位置を示す双方向反復子。

  • _Last
    仕切られるする範囲の最後の要素の一つ前の位置 1 に対処双方向反復子。

  • _Pred
    要素を使用する場合は、満たされている必要条件を定義するユーザー定義の述語関数オブジェクト。述語は、一つの引数を受け取り、truefalseを返します。

戻り値

述語条件が満たされない場合、範囲の最初の要素の位置を示す双方向反復子。

解説

参照される範囲が有効である必要があります; すべてのポインターが dereferenceable なり、シーケンス内で最後の位置は incrementation によって最初からアクセスできます。

要素 a および b は同等ですが、もし 指定された述語 Pr において、Pr (a, b) が両方 false で、かつ Pr( b, a) が false の場合、必ずしも等しくはありません。stable_ partition のアルゴリズムは同等の要素の相対的な命令が保存されるという保証安定してです。アルゴリズム partition は、この元の順序を保持しません。

使用例

// alg_stable_partition.cpp
// compile with: /EHsc
#include <vector>
#include <algorithm>
#include <iostream>

bool greater5 ( int value ) {
   return value >5;
}

int main( ) {
   using namespace std;
   vector <int> v1, v2;
   vector <int>::iterator Iter1, Iter2, result;

   int i;
   for ( i = 0 ; i <= 10 ; i++ )
      v1.push_back( i );

   int ii;
   for ( ii = 0 ; ii <= 4 ; ii++ )
      v1.push_back( 5 );

   random_shuffle(v1.begin( ), v1.end( ) );

   cout << "Vector v1 is ( " ;
   for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
      cout << *Iter1 << " ";
   cout << ")." << endl;

   // Partition the range with predicate greater10
   result = stable_partition (v1.begin( ), v1.end( ), greater5 );
   cout << "The partitioned set of elements in v1 is:\n ( " ;
   for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
      cout << *Iter1 << " ";
   cout << ")." << endl;

   cout << "The first element in v1 to fail to satisfy the"
        << "\n predicate greater5 is: " << *result << "." << endl;
}

出力例

Vector v1 is ( 5 1 9 2 0 5 7 3 4 5 8 5 5 5 10 6 ).
The partitioned set of elements in v1 is:
 ( 9 7 8 10 6 5 1 2 0 5 3 4 5 5 5 5 ).
The first element in v1 to fail to satisfy the
 predicate greater5 is: 5.

必要条件

ヘッダー: <algorithm>

名前空間: std

参照

関連項目

標準テンプレート ライブラリ