The Wayback Machine - https://web.archive.org/web/20180511082952/http://fr.cppreference.com:80/w/cpp/algorithm/remove
Espaces de noms
Variantes
Actions

std::remove, std::remove_if

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.
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.
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.
 
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)
Supprime tous les éléments répondant à des critères spécifiques de la gamme [first, last). La première version supprime tous les éléments qui sont égaux à value, la deuxième version supprime tous les éléments pour lesquels prédicat retourne ptrue .
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.
D'élimination est effectuée en déplaçant les éléments de la gamme, de telle manière que les éléments à effacer sont écrasés. Les éléments entre les anciens et les nouveaux extrémités de la gamme des valeurs non spécifiées. Un itérateur à la nouvelle extrémité de la gamme est retourné. Ordre relatif des éléments qui demeurent soit préservée .
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.

Sommaire

[modifier]Paramètres

first, last -
l'ensemble d'éléments de processus
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 -
la valeur des éléments à supprimer
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 l'élément doit être supprimé
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.

[modifier]Retourne la valeur

Itérateur à la nouvelle extrémité de la gamme
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.

[modifier]Complexité

Exactement std::distance(first, last) applications du prédicat .
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.

[modifier]Notes

Les fonctions de même nom list::remove membres de conteneurs, list::remove_if, forward_list::remove et forward_list::remove_if effacer les éléments supprimés .
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.

[modifier]Mise en œuvre possible

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

[modifier]Exemple

Le code suivant supprime tous les espaces d'une chaîne en les déplaçant vers la fin de la chaîne, puis effacer .
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';}

Résultat :

Textwithsomespaces

[modifier]Voir aussi

Copie une série d'éléments en omettant ceux qui satisfont à certains critères
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.

(fonction générique)[edit]
close