remove_if
语法:
1 |
void remove_if( UnPred pr ); |
remove_if()以一元谓词pr为判断元素的依据,遍历整个链表。如果pr返回true则删除该元素。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
源代码 /** * @brief Remove all elements satisfying a predicate. * @param Predicate Unary predicate function or object. * * Removes every element in the list for which the predicate * returns true. Remaining elements stay in list order. Note * that this function only erases the elements, and that if the * elements themselves are pointers, the pointed-to memory is * not touched in any way. Managing the pointer is the user's * responsibilty. */ template<typename _Predicate> void remove_if(_Predicate); |
测试代码
测试结果
20
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9
10
0 1 2 3 4 5 6 7 8 9