From 19e38a641dc371a4132c943a6cec247d35fdb1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Thu, 27 Nov 2014 11:15:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90remove=E5=92=8Cremove=5Fif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/List.h | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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