Espacios de nombres
Variantes
Acciones

std::remove, std::remove_if

De cppreference.com
< cpp‎ | algorithm

 
 
Algoritmo biblioteca
Funciones
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Para no modificar la secuencia de las operaciones
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.
Modificación de la secuencia de operaciones
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.
Particionamiento operaciones
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.
Clasificación de las operaciones (en rangos ordenados)
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.
Las operaciones binarias de búsqueda (en rangos ordenados)
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.
Conjunto de operaciones (en rangos ordenados)
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.
Operaciones del montón
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.
Mínimo / máximo de operaciones
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.
Operaciones numéricas
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 biblioteca
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.
 
Defined in header <algorithm>
template< class ForwardIt, class T >
ForwardIt remove( ForwardIt first, ForwardIt last, const T& value );
(1)
template< class ForwardIt, class UnaryPredicate >
ForwardIt remove_if( ForwardIt first, ForwardIt last, UnaryPredicate p );
(2)
Quita todos los elementos que cumplan criterios específicos de la [first, last) rango. La primera versión elimina todos los elementos que son iguales a value, la segunda versión elimina todos los elementos para los que predicado p vuelve true .
Original:
Removes all elements satisfying specific criteria from the range [first, last). The first version removes all elements that are equal to value, the second version removes all elements for which predicate p returns true.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Extracción se realiza desplazando los elementos en el intervalo de tal manera que los elementos que se borren se sobrescriben. Los elementos entre los antiguos y los nuevos fines de la gama tienen valores no especificados. Un iterador al nuevo extremo de la gama se devuelve. Orden relativo de los elementos que permanecen se conserva .
Original:
Removing is done by shifting the elements in the range in such a way that elements to be erased are overwritten. The elements between the old and the new ends of the range have unspecified values. An iterator to the new end of the range is returned. Relative order of the elements that remain is preserved.
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 -
el intervalo de elementos de proceso
Original:
the range of elements to process
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
value -
el valor de los elementos que desea eliminar
Original:
the value of elements to remove
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
si el elemento debe ser eliminado
Original:
if the element should be removed
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 ForwardIt can be dereferenced and then implicitly converted to Type. ​

Type requirements
-
ForwardIt must meet the requirements of ForwardIterator.
-
The type of dereferenced ForwardIt must meet the requirements of MoveAssignable.

[editar] Valor de retorno

Iterator al nuevo extremo de la gama
Original:
Iterator to the new end of the 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 std::distance(first, last) aplicaciones del predicado .
Original:
Exactly std::distance(first, last) applications of the predicate.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Notas

Las funciones de contenedores con nombres similares miembro list::remove, list::remove_if, forward_list::remove y forward_list::remove_if borrar los elementos eliminados .
Original:
The similarly-named container member functions list::remove, list::remove_if, forward_list::remove, and forward_list::remove_if erase the removed elements.
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

First version
template<class ForwardIt, class T>
ForwardIt remove(ForwardIt first, ForwardIt last, 
                       const T& value)
{
    ForwardIt result = first;
    for (; first != last; ++first) {
        if (!(*first == value)) {
            *result++ = *first;
        }
    }
    return result;
}
Second version
template<class ForwardIt, class UnaryPredicate>
ForwardIt remove_if(ForwardIt first, ForwardIt last, 
                          UnaryPredicate p)
{
    ForwardIt result = first;
    for (; first != last; ++first) {
        if (!p(*first)) {
            *result++ = *first;
        }
    }
    return result;
}

[editar] Ejemplo

El código siguiente quita todos los espacios de una cadena moviéndolos hasta el final de la cadena y luego borrar .
Original:
The following code removes all spaces from a string by moving them to the end of the string and then erasing.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <algorithm>
#include <string>
#include <iostream>
int main()
{
    std::string str = "Text with some   spaces";
    str.erase(std::remove(str.begin(), str.end(), ' '),
              str.end());
    std::cout << str << '\n';
}

Output:

Textwithsomespaces

[editar] Ver también

Copia un intervalo de elementos omitiendo los que satisfacen criterios específicos
Original:
copies a range of elements omitting those that satisfy specific criteria
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]