std::partition_copy
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <algorithm>
|
||
| template< class InputIt, class OutputIt1, class OutputIt2, class UnaryPredicate > |
(C++11 起) | |
p從[first, last)的範圍的範圍內開始,d_first_true,和複製元素沒有開始的範圍內,在滿足pd_first_false.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.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:
The signature does not need to have const &, but the function must not modify the objects passed to it. | |||||||||
| Type requirements | |||||||||||
-InputIt must meet the requirements of InputIterator.
| |||||||||||
-OutputIt1 must meet the requirements of OutputIterator.
| |||||||||||
-OutputIt2 must meet the requirements of OutputIterator.
| |||||||||||
[编辑] 返回值
d_first_true範圍和d_first_false範圍的結束迭代器迭代器.d_first_true range and the iterator to the end of the d_first_false range.You can help to correct and verify the translation. Click here for instructions.
[编辑] 複雜性
distance(first, last)應用程序的pdistance(first, last) applications of p.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; } return std::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'; return 0; }
Output:
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. (函數模板) | |
| 將元素分為兩組,同時保留其相對順序 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. (函數模板) | |