[ Web Proxy ]
URL:
Viewing: https://fr.cppreference.com/cpp/algorithm/remove [Back]  [Original]

std::remove, std::remove_if cppreference.com
cppreference.com
Espaces de noms
Variantes

std::remove, std::remove_if

De cppreference.com

<metanoindex/>

 
 
Bibliothque 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 squence des oprations
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 squence des oprations
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 oprations 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.
Oprations de tri (sur les gammes tris)
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.
is_sorted (C++11)
is_sorted_until (C++11)
sort
Oprations binaires de recherche (sur les gammes tris)
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.
Dfinir les oprations (sur les gammes tris)
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.
Oprations 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.
Oprations numriques
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.
Bibliothque 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.
 
<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.
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.

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 p(v) doit pouvoir tre convertie bool pour tout argument v de type (possiblement const) VT, o VT est le type de valeur de ForwardIt, inconditionellement de value category, et ne doit pas modifier v. Ainsi, un type-paramtre VT&n'est pas permis ainsi que pour VT sauf pour VT un dplacement est quivalent une copie (depuis C++11).

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.

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.

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.

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.

#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) [edit]

Web Proxy Viewer  |  New URL  |  Original Page