std::remove, std::remove_if
De cppreference.com
[] |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody>| Dclar dans l'en-tte <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 lments rpondant des critres spcifiques de la gamme
[first, last). La premire version supprime tous les lments qui sont gaux value, la deuxime version supprime tous les lments pour lesquels prdicat retourne p 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.
You can help to correct and verify the translation. Click here for instructions.
D'limination est effectue en dplaant les lments de la gamme, de telle manire que les lments effacer sont crass. Les lments entre les anciens et les nouveaux extrmits de la gamme des valeurs non spcifies. Un itrateur la nouvelle extrmit de la gamme est retourn. Ordre relatif des lments qui demeurent soit prserve .
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.
You can help to correct and verify the translation. Click here for instructions.
Paramtres
| first, last | - | l'ensemble d'lments 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 lments 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 | - | prdicat unaire qui retourne true si l'lment 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. L'expression |
| Type requirements | ||
-ForwardIt must meet the requirements of ForwardIterator.
| ||
-The type of dereferenced ForwardIt must meet the requirements of MoveAssignable.
| ||
Retourne la valeur
Itrateur la nouvelle extrmit 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.
You can help to correct and verify the translation. Click here for instructions.
Complexit
Exactement
std::distance(first, last) applications du prdicat .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.
You can help to correct and verify the translation. Click here for instructions.
Notes
Les fonctions de mme nom list::remove membres de conteneurs, list::remove_if, forward_list::remove et forward_list::remove_if effacer les lments supprims .
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.
You can help to correct and verify the translation. Click here for instructions.
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;
}
|
Exemple
Le code suivant supprime tous les espaces d'une chane en les dplaant vers la fin de la chane, 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.
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';
}
Rsultat :
Textwithsomespaces
Voir aussi
Copie une srie d'lments en omettant ceux qui satisfont certains critres 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 gnrique) | |