Predicate pred can be implemented as any typed expression taking one argument of the same type as the list and returning a bool (this may either be a function pointer or an object whose class implements operator().
The function calls pred(*i) for each element (where i is an iterator to that element). Any of the elements in the list for which this returns true, is removed from the container.
Notice that a global algorithm function, remove_if, exists with a similar behavior but operating between two iterators.
Parameters
- pred
- Unary predicate that, taking a value of the same type as those contained in the list object, returns true for those values to be removed from the container, and false for those remaining.
Return value
noneExample
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
Output:
mylist contains: 36 20 |
Complexity
Linear in list::size (predicates).See also
| list::remove | Remove elements with specific value (public member function) |
| list::erase | Erase elements (public member function) |
| list::unique | Remove duplicate values (member function) |
| list::pop_back | Delete last element (public member function) |
| list::pop_front | Delete first element (public member function) |
