المتغيرات
فضاءات التسمية
أفعال

std::{{{1}}}::remove, remove_if

من cppreference.com
void remove( const T& value );
قالب:mark since none
template< class UnaryPredicate >
void remove_if( UnaryPredicate p );
قالب:mark since none

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.

محتويات

[تعديل] Parameters

value - value of the elements to remove

قالب:par pred1

[تعديل] Return value

(none)

[تعديل] Complexity

Linear in the size of the container

[تعديل] Example

#include <{{{1}}}>
#include <iostream>
 
int main()
{
    std::{{{1}}}<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';
}

الخرج:

2 3 10 -1

[تعديل] See also

قالب:dsc tfun