diff --git a/TinySTL/List.h b/TinySTL/List.h index b2dfed6..4d32d27 100644 --- a/TinySTL/List.h +++ b/TinySTL/List.h @@ -137,9 +137,9 @@ namespace TinySTL{ //void splice(iterator position, list& x); //void splice(iterator position, list& x, iterator i); //void splice(iterator position, list& x, iterator first, iterator last); - //void remove(const value_type& val); - //template - //void remove_if(Predicate pred); + void remove(const value_type& val); + template + void remove_if(Predicate pred); //void unique(); //template //void unique(BinaryPredicate binary_pred); @@ -265,6 +265,25 @@ namespace TinySTL{ curNode = nextNode; } while (curNode != head.p); } + template + void List::remove(const value_type& val){ + for (auto it = begin(); it != end();){ + if (*it == val) + it = erase(it); + else + ++it; + } + } + template + template + void List::remove_if(Predicate pred){ + for (auto it = begin(); it != end();){ + if (pred(*it)) + it = erase(it); + else + ++it; + } + } } #endif \ No newline at end of file