std::list::remove, std::list::remove_if
De cppreference.com
<metanoindex/>
<tbody> </tbody> void remove( const T& value ); |
||
template< class UnaryPredicate > void remove_if( UnaryPredicate p ); |
||
Remove todos os elementos que satisfazem critérios específicos. A primeira versão remove todos os elementos que são iguais a
value, a segunda versão remove todos os elementos para que predicado p retornos 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.
You can help to correct and verify the translation. Click here for instructions.
Parâmetros
| value | - | valor dos elementos a serem removidos
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 | - | unary predicate which returns true se o elemento deve ser removido . 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:
The signature does not need to have |
Valor de retorno
(Nenhum)
Original:
(none)
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.
Complexidade
linear no tamanho do recipiente
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.
You can help to correct and verify the translation. Click here for instructions.
Exemplo
#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';
}
Saída:
2 3 10 -1
