Improve list::clear

This commit is contained in:
Henrique Gemignani Passos Lima 2022-10-20 17:10:03 +03:00
parent 1a83aa2aac
commit 16cb68c709
No known key found for this signature in database
GPG Key ID: E224F951761145F8
1 changed files with 8 additions and 10 deletions

View File

@ -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;