Espaces de noms
Variantes
Affichages
Actions

std::partition_copy

De cppreference.com
< cpp‎ | algorithm

 
 
Bibliothèque d'algorithmes
Fonctions
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Non-modification de la séquence des opérations
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.
Modification de la séquence des opérations
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.
Des opérations de partitionnement
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)
Opérations de tri (sur les gammes triés)
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.
is_sorted (C++11)
is_sorted_until (C++11)
sort
Opérations binaires de recherche (sur les gammes triés)
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.
Définir les opérations (sur les gammes triés)
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.
Opérations Heap
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.
Minimum / maximum de fonctionnement
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.
Opérations numériques
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.
Bibliothèque 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.
 
Déclaré dans l'en-tête <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);
(depuis C++11)
Copie les éléments qui satisfont le prédicat p de la plage [first, last) au début plage à d_first_true, et copie les éléments qui ne satisfont pas p au début plage à 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.

Sommaire

[modifier] Paramètres

first, last -
la plage d'éléments à trier
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 -
le début de la plage de sortie pour les éléments qui satisfont 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 -
le début de la plage de sortie pour les éléments qui ne satisfont pas 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 - prédicat unéaire qui retourne ​true
si l'élément doit être placé dans 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.
.

L'expression p(v) doit pouvoir être convertie à bool pour tout argument v de type (possiblement const) VT, où VT est le type de valeur de InputIt, inconditionellement de value category, et ne doit pas modifier v. Ainsi, un type-paramètre VT&n'est pas permis ainsi que pour VT sauf pour VT un déplacement est équivalent à une copie (depuis C++11). ​

Type requirements
-
InputIt must meet the requirements of InputIterator.
-
OutputIt1 must meet the requirements of OutputIterator.
-
OutputIt2 must meet the requirements of OutputIterator.

[modifier] Retourne la valeur

Un pair construit à partir de l'itérateur à la fin de l'intervalle d_first_true et l'itérateur à la fin de l'intervalle 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.

[modifier] Complexité

Exactement distance(first, last) applications de 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.

[modifier] Mise en œuvre possible

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);
}

[modifier] Exemple

#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;
 
}

Résultat :

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

[modifier] Voir aussi

divise une série d'éléments en deux groupes
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.

(fonction générique) [edit]
divise les éléments en deux groupes, tout en préservant leur ordre relatif
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.

(fonction générique) [edit]