partition_copy, is_partitioned, partition_point
template <class InputIterator, class OutputIterator1, class OutputIterator2, class Predicate> pair<OutputIterator1, OutputIterator2> partition_copy(InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
シーケンス[first,last)の各要素xをpred(x)がtrueならout_true、falseならout_falseにコピーし、処理終了時のふたつのOutputIterator値をpairにして返します。
template <class InputIterator, class Predicate> bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
シーケンス[first,last)の各要素xがpred(x)がtrueとなる前半部とfalseとなる後半部に分割されていればtrueを返します。
template <class ForwardIterator, class Predicate> ForwardIterator partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
predに基づいて分割されたシーケンス[first,last)に対し、その分割点すなわち後半部の最初の要素を指すイテレータを返します。
……つづき
// partition_copy
ia5 evens;
ia5 odds;
pair<ia5::iterator,ia5::iterator> lasts =
partition_copy(c.begin(), c.end(), evens.begin(), odds.begin(), u_even); // 偶数をevens, それ以外をoddsへ
assert( accumulate(evens.begin(), lasts.first, 0) == 12 );
assert( accumulate(odds.begin(), lasts.second, 0) == 8 );
// is_partitioned
result = is_partitioned(c.begin(), c.end(), [](int n) { return n < 5;}); // 5未満とそれ以外に分割されてる?
assert( result );
result = is_partitioned(c.begin(), c.end(), u_even); // 偶数と奇数では?
assert( !result );
// partition_point
iter = partition_point(c.begin(), c.end(), [](int n){return n < 5;});
assert( distance(c.begin(),iter) == 3 );
……つづく
is_sorted, is_sorted_until
template <class ForwardIterator, class Predicate> bool is_sorted(ForwardIterator first, ForwardIterator last, Predicate pred);
predが示す大小関係に基づき、シーケンス[first,last)がソートされていればtrueを返します。predが省略されていた場合、operator<が適用されます。
template <class ForwardIterator, class Predicate> ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last, Predicate pred);
is_sorted(first,mid,pred)がtrueとなる最大のmidを返します。predが省略されていた場合、operator<が適用されます。
現時点でvc10のis_sorted_untilにはバグがありますが、ヘッダ<algorithm>にパッチをあてることで解消できそうです。詳しくはMicrosoft Connectを参照。
……つづき
// is_sorted
result = is_sorted(c.begin(), c.end(), [](int x, int y) { return x < y; }); // 昇順か?
assert( result );
result = is_sorted(c.begin(), c.end(), [](int x, int y) { return x > y; }); // 降順か?
assert( !result );
// is_sorted_until
c[4] = 0;
iter = is_sorted_until(c.begin(), c.end(), [](int x, int y) { return x < y;}); // どこまで昇順?
assert( distance(c.begin(), iter) == 4 ); // 注意!! vc10 <algorithm> にバグあり!
……つづく
