std::partition_copy
Aus cppreference.com
|
|
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. |
<metanoindex/>
<tbody> </tbody>| definiert in Header <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); |
(seit C++11) | |
Kopiert die Elemente, die das Prädikat
p aus dem Bereich [first, last) auf den Bereich beginnend bei d_first_true befriedigen, und kopiert die Elemente, die nicht erfüllen p auf den Bereich beginnend bei 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.
You can help to correct and verify the translation. Click here for instructions.
Parameter
| first, last | - | der Bereich von Elementen zu sortieren
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 | - | der Beginn der Ausgangsbereich für die Elemente, die p erfüllen
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 | - | der Beginn der Ausgangsbereich für die Elemente nicht erfüllen 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 wenn das Element sollte d_first_true abgegeben werden . 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 |
| Type requirements | ||
-InputIt must meet the requirements of InputIterator.
| ||
-OutputIt1 must meet the requirements of OutputIterator.
| ||
-OutputIt2 must meet the requirements of OutputIterator.
| ||
Rückgabewert
A
pair aus dem Iterator auf das Ende des d_first_true Bereich und der Iterator auf das Ende des d_first_false Bereich gebaut .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.
You can help to correct and verify the translation. Click here for instructions.
Komplexität
Genau
distance(first, last) Anwendungen 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.
You can help to correct and verify the translation. Click here for instructions.
Mögliche Implementierung
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);
}
|
Beispiel
#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
Siehe auch
teilt einen Bereich von Elementen in zwei Gruppen 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. (Funktions-Template) | |
trennt Elemente in zwei Gruppen unter Beibehaltung ihrer relativen Ordnung 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. (Funktions-Template) | |