std::remove, std::remove_if
|
|
Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.
La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
| Definido en el archivo de encabezado <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) | |
[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 . [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. 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.
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 | - | Predicado unario que devuelve 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. La signatura de la función predicado debe ser equivalente a: bool pred(const Type &a); La forma no necesita tener const &, pero la función no debe modificar el objeto que se ha pasado. |
| Requerimientos de tipo | ||
-ForwardIt debe reunir los requerimientos de ForwardIterator.
| ||
-The type of dereferenced ForwardIt must meet the requirements of MoveAssignable.
| ||
[editar] Valor de retorno
You can help to correct and verify the translation. Click here for instructions.
[editar] Complejidad
You can help to correct and verify the translation. Click here for instructions.
[editar] Notas
You can help to correct and verify the translation. Click here for instructions.
[editar] Posible implementación
| Primera versión |
|---|
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; } |
| Segunda versión |
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
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'; }
Salida:
Textwithsomespaces
[editar] Ver también
| Copia un rango de elementos omitiendo los que satisfacen un criterio específico (plantilla de función) |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
