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

std::partition_copy

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を非改変
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を変更する
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
操作を仕切る
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is_partitioned(C++11)
partition
partition_copy(C++11)
(ソートされた範囲で)ソート操作
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイナリ検索操作(ソート範囲で)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)操作を設定します
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ヒープ操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小値/最大値操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
数値演算
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
ヘッダ <algorithm> で定義
template<class InputIt, class OutputIt1,

          class OutputIt2, class UnaryPredicate >
std::pair<OutputIt1, OutputIt2>
     partition_copy(InputIt first, InputIt last,
                    OutputIt1 d_first_true, OutputIt2 d_first_false,

                    UnaryPredicate p);
(C++11およびそれ以降)
pでレンジ[first, last)から範囲の先頭に述語d_first_trueを満たす要素をコピーし、pでレンジ先頭にd_first_falseを満たさない要素がコピーされます.
Original:
Copies the elements that satisfy the predicate p from the range [first, last) to the range beginning at d_first_true, and copies the elements that do not satisfy p to the range beginning at d_first_false.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集]パラメータ

first, last -
ソートする要素の範囲
Original:
the range of elements to sort
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d_first_true -
pを満たす要素の出力範囲の始まり
Original:
the beginning of the output range for the elements that satisfy p
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d_first_false -
pを満たさない要素の出力範囲の始まり
Original:
the beginning of the output range for the elements that do not satisfy p
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
p - unary predicate which returns ​true
要素がd_first_trueに配置する必要があるかどうか
Original:
if the element should be placed in d_first_true
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.

The signature of the predicate function should be equivalent to the following:

 bool pred(const Type &a);

The signature does not need to have const&, but the function must not modify the objects passed to it.
The type Type must be such that an object of type InputIt can be dereferenced and then implicitly converted to Type. ​

型の要件
-
InputItInputIterator

の要求を満足しなければなりません。

-
OutputIt1OutputIterator

の要求を満足しなければなりません。

-
OutputIt2OutputIterator

の要求を満足しなければなりません。

[編集]値を返します

イテレータからpair範囲とd_first_true範囲の末尾を指すイテレータの最後に構築d_first_false.
Original:
A pair constructed from the iterator to the end of the d_first_true range and the iterator to the end of the d_first_false range.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]複雑性

distance(first, last)の正確pアプリケーション.
Original:
Exactly distance(first, last) applications of p.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]可能な実装

template<class InputIt, class OutputIt1, class OutputIt2, class UnaryPredicate>std::pair<OutputIt1, OutputIt2> partition_copy(InputIt first, InputIt last, OutputIt1 d_first_true, OutputIt2 d_first_false, UnaryPredicate p){while(first != last){if(p(*first)){*d_first_true =*first;++d_first_true;}else{*d_first_false =*first;++d_first_false;}++first;}returnstd::pair<OutputIt1, OutputIt2>(d_first_true, d_first_false);}

[編集]

#include <iostream>#include <algorithm>#include <utility>   int main(){int arr [10]={1,2,3,4,5,6,7,8,9,10};int true_arr [5]={0};int false_arr [5]={0};   std::partition_copy(std::begin(arr), std::end(arr), std::begin(true_arr),std::begin(false_arr), [](int i){return i >5;});   std::cout<<"true_arr: ";for(auto it =std::begin(true_arr); it !=std::end(true_arr);++it){std::cout<<*it <<' ';}std::cout<<'\n';   std::cout<<"false_arr: ";for(auto it =std::begin(false_arr); it !=std::end(false_arr);++it){std::cout<<*it <<' ';}std::cout<<'\n';   return0;   }

出力:

true_arr: 6 7 8 9 10 false_arr: 1 2 3 4 5

[編集]参照

二つのグループに要素の範囲を分割します
Original:
divides a range of elements into two groups
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート)[edit]
それらの相対的な順序を維持しながら、二つのグループに要素を分割します
Original:
divides elements into two groups while preserving their relative order
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート)[edit]
close