diff --git a/include/rstl/list.hpp b/include/rstl/list.hpp index d8f735e0..c3dc4522 100644 --- a/include/rstl/list.hpp +++ b/include/rstl/list.hpp @@ -35,16 +35,7 @@ public: } void push_back(const T& val) { do_insert_before(x8_end, val); } void clear() { - // iterator e = end(); - iterator cur = begin(); - while (cur != end()) { - cur = erase(cur); - } - // node *e = x8_end; - // node *cur = x4_start; - // while (cur != e) { - // cur = erase(cur); - // } + erase(begin(), end()); } iterator begin() { return iterator(x4_start); } @@ -52,6 +43,13 @@ public: iterator end() { return iterator(x8_end); } const_iterator end() const { return const_iterator(x8_end); } + void erase(const iterator& start, const iterator& end) { + iterator it = start; + while (it != end) { + erase(it++); + } + } + private: struct node { node* x0_prev;