◐ Shell
clean mode source ↗

std::list::remove, std::list::remove_if — cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

void remove( const T& value );

template< class UnaryPredicate > void remove_if( UnaryPredicate p );

Supprime tous les éléments répondant à des critères spécifiques. 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 p true .

Original:

Removes all elements satisfying specific criteria. 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.

Paramètres

value -

valeur des éléments à supprimer

Original:

value of the 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 - prédicat unéaire qui retourne ​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.

.

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 list<T,Allocator>::const_iterator, inconditionellement de value category, et ne doit pas modifier v. Ainsi, un type-paramètre VT&n'est pas permis ainsi que pour VT sauf pour VT un déplacement est équivalent à une copie (depuis C++11). ​

Retourne la valeur

(Aucun)

Original:

(none)

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Complexité

linéaire à la taille du récipient

Original:

linear in the size of the container

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Exemple

#include <list>
#include <iostream>

int main()
{
    std::list<int> l = { 1,100,2,3,10,1,11,-1,12 };

    l.remove(1); // remove both elements equal to 1
    l.remove_if([](int n){ return n > 10; }); // remove all elements greater than 10

    for (int n : l) {
        std::cout << n << ' '; 
    }
    std::cout << '\n';
}

Résultat :

Voir aussi

supprime des éléments répondant à des critères spécifiques

Original:

removes elements satisfying 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]