Espacios de nombres
Variantes
Acciones

std::partition_copy

De cppreference.com
< cpp‎ | algorithm
 
 
Biblioteca de algoritmos
Políticas de ejecución (C++17)
Operaciones de secuencia no modificantes
(C++11)(C++11)(C++11)
(C++17)
Operaciones de secuencia modificantes
Operaciones en almacenamiento no inicializado
Operaciones de partición
partition_copy
(C++11)
Operaciones de ordenación
Operaciones de búsqueda binaria
Operaciones de conjuntos (en rangos ordenados)
Operaciones de pila
(C++11)
Operaciones mínimo/máximo
(C++11)
(C++17)
Permutaciones
Operaciones numéricas
Bibliotecas C
 
Definido en el archivo de encabezado <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);
(desde C++11)
Copia los elementos que satisfacen el predicado de la p[first, last) amplia gama de principios en d_first_true y copia los elementos que no cumplan p al inicio de arena a 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.

Contenido

[editar]Parámetros

first, last -
la gama de elementos a ordenar
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 -
el comienzo del rango de salida para los elementos que satisfacen 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 -
el comienzo del rango de salida para los elementos que no satisfacen 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 - Predicado unario que devuelve ​true
si el elemento debe ser colocado en 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.
.

La expresión p(v) debe ser convertible a bool para cada argumento v de tipo (posiblemente const) VT, donde VT es el tipo valor de InputIt, independientemente de la categoría de valor, y no debe modificar v. Por lo tanto, no se admite un parámetro de tipo VT&, ni es VT a menos que para VT una operación de movimiento sea equivalente a una copia(desde C++11). ​

Requisitos de tipo
-
InputIt debe reunir los requerimientos de InputIterator.
-
OutputIt1 debe reunir los requerimientos de OutputIterator.
-
OutputIt2 debe reunir los requerimientos de OutputIterator.

[editar]Valor de retorno

Un pair construido a partir de la iterador al final del intervalo de d_first_true y el iterador al final del intervalo de 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.

[editar]Complejidad

Exactamente distance(first, last) aplicaciones 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.

[editar]Posible implementación

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

[editar]Ejemplo

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

Salida:

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

[editar]Ver también

Divide un rango de elementos en dos grupos.
(plantilla de función)[editar]
Divide elementos en dos grupos, conservando su orden relativo.
(plantilla de función)[editar]
close