From 78419238f909dc2af0bb5740c71052f7a570fa49 Mon Sep 17 00:00:00 2001 From: Bertrand Augereau Date: Sun, 30 Mar 2008 06:37:46 +0000 Subject: The "anchor" (root) of the linked list is now constructed inplace in the List instead of being newed (it has the same lifetime as the List itself anyway) svn-id: r31323 --- common/list.h | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/common/list.h b/common/list.h index 08b964eddf..5629c40a0d 100644 --- a/common/list.h +++ b/common/list.h @@ -111,7 +111,7 @@ public: } }; - NodeBase *_anchor; + NodeBase _anchor; public: typedef Iterator iterator; @@ -121,21 +121,18 @@ public: public: List() { - _anchor = new NodeBase; - _anchor->_prev = _anchor; - _anchor->_next = _anchor; + _anchor._prev = &_anchor; + _anchor._next = &_anchor; } List(const List& list) { - _anchor = new NodeBase; - _anchor->_prev = _anchor; - _anchor->_next = _anchor; + _anchor._prev = &_anchor; + _anchor._next = &_anchor; insert(begin(), list.begin(), list.end()); } ~List() { clear(); - delete _anchor; } void push_front(const t_T& element) { @@ -232,32 +229,32 @@ public: } bool empty() const { - return (_anchor == _anchor->_next); + return (&_anchor == _anchor._next); } iterator begin() { - return iterator(_anchor->_next); + return iterator(_anchor._next); } iterator reverse_begin() { - return iterator(_anchor->_prev); + return iterator(_anchor._prev); } iterator end() { - return iterator(_anchor); + return iterator(&_anchor); } const_iterator begin() const { - return const_iterator(_anchor->_next); + return const_iterator(_anchor._next); } const_iterator reverse_begin() const { - return const_iterator(_anchor->_prev); + return const_iterator(_anchor._prev); } const_iterator end() const { - return const_iterator(_anchor); + return const_iterator(const_cast(&_anchor)); } }; -- cgit v1.2.3