(C++17) | ||||
| Sequence | ||||
(C++11) | ||||
(C++26) | ||||
(C++26) | ||||
(C++11) | ||||
| Associative | ||||
| Unordered associative | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Adaptors | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
| Views | ||||
(C++20) | ||||
(C++23) | ||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
| Member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Deduction guides(C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (1) | ||
void remove(const T& value); | (since C++11) (until C++20) | |
size_type remove(const T& value); | (since C++20) (constexpr since C++26) | |
| (2) | ||
template<class UnaryPred> void remove_if( UnaryPred p); | (since C++11) (until C++20) | |
template<class UnaryPred> size_type remove_if( UnaryPred p); | (since C++20) (constexpr since C++26) | |
Removes all elements satisfying specific criteria.
Invalidates only the iterators and references to the removed elements.
Contents |
| value | - | value of the elements to remove |
| p | - | unary predicate which returns true if the element should be removed. The expressionp(v) must be convertible tobool for every argument |
| Type requirements | ||
-UnaryPred must meet the requirements ofPredicate. | ||
(none) | (until C++20) |
The number of elements removed. | (since C++20) |
Given\(\scriptsize N\)N asstd::distance(begin(), end()):
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_list_remove_return_type | 201806L | (C++20) | Change the return type |
#include <forward_list>#include <iostream> int main(){std::forward_list<int> l={1,100,2,3,10,1,11,-1,12}; auto count1= l.remove(1);std::cout<< count1<<" elements equal to 1 were removed\n"; auto count2= l.remove_if([](int n){return n>10;});std::cout<< count2<<" elements greater than 10 were removed\n"; std::cout<<"Finally, the list contains: ";for(int n: l)std::cout<< n<<' ';std::cout<<'\n';}
Output:
2 elements equal to 1 were removed3 elements greater than 10 were removedFinally, the list contains: 2 3 10 -1
| removes elements satisfying specific criteria (function template)[edit] |