diff --git a/.gitignore b/.gitignore index 41a36d0..81ce15c 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ gmon\.out *.exe *.out *.app +debug/* diff --git a/src/list.hh b/src/list.hh index 1e303ae..85f5d9a 100644 --- a/src/list.hh +++ b/src/list.hh @@ -205,6 +205,8 @@ public: // Modifiers // ///////////////////////////////////////////////////////////////////////////// + // clear //////////////////////////////////////////////////////////////////// + void clear() { cell *it = sentry->n; while (it != sentry) { @@ -214,6 +216,8 @@ public: } } + // insert /////////////////////////////////////////////////////////////////// + iterator insert(const_iterator pos, const T &value) { cell *elem = new cell{value}; elem->n = pos; @@ -239,7 +243,62 @@ public: return iterator{pos}; } + // emplace ////////////////////////////////////////////////////////////////// + template + iterator emplace(const_iterator pos, Args&&... args) { + return insert(pos, T{std::forward(args)...}); + } + + // erase //////////////////////////////////////////////////////////////////// + + iterator erase(const_iterator pos) { + pos->p->n = pos->n; + pos->n->p = pos->p; + pos->n = nullptr; + pos->p = nullptr; + cell* todel = pos; + ++pos; + delete todel; + return pos; + } + + iterator erase(const_iterator begin, const_iterator end) { + while(begin != end) { + begin = erase(begin); + } + return begin; + } + + // push_back //////////////////////////////////////////////////////////////// + + void push_back(const T &v) { + cell *c = new cell; + c->x = v; + c->p = sentry->p; + c->n = sentry; + sentry->p->n = c; + sentry->p = c; + } + + void push_back(T&& v) { + cell *c = new cell; + std::swap(c->x, v); + c->p = sentry->p; + c->n = sentry; + sentry->p->n = c; + sentry->p = c; + } + + // emplace_back ///////////////////////////////////////////////////////////// + + template + T& emplace_back(Args&&... args) { + emplace(begin(), args...); + return *begin(); + } + + // pop_back ///////////////////////////////////////////////////////////////// bool empty() { return sentry->p == sentry; } @@ -252,15 +311,6 @@ public: sentry->n = c; } - void push_back(const T &v) { - cell *c = new cell; - c->x = v; - c->p = sentry->p; - c->n = sentry; - sentry->p->n = c; - sentry->p = c; - } - void pop_front() { cell *c = sentry->n; sentry->n = c->n;