24 #ifndef mySTL_LIST_HPP
25 #define mySTL_LIST_HPP
28 #include "helpers.hpp"
47 node(T t) : prev_(0), next_(0), value_(t) {}
54 list() : head_(0), tail_(0), sz_(0) {}
64 size_t size()
const {
return sz_; }
65 bool empty()
const {
return sz_ == 0; }
70 explicit iterator(node* p = 0) : current_(p) {}
74 return current_->value_;
79 return &(operator*());
84 current_ = current_->next_;
90 current_ = current_->prev_;
97 current_ = current_->next_;
104 current_ = current_->prev_;
108 bool operator==(
const iterator& other)
const
110 return current_ == other.current_;
113 bool operator!=(
const iterator& other)
const
115 return current_ != other.current_;
118 friend class list<T>;
129 return current_->value_;
132 T* operator->()
const
134 return &(operator*());
139 current_ = current_->prev_;
145 current_ = current_->next_;
152 current_ = current_->prev_;
159 current_ = current_->next_;
165 return current_ == other.current_;
170 return current_ != other.current_;
173 friend class list<T>;
179 reverse_iterator rbegin()
const {
return reverse_iterator(tail_); }
180 iterator end()
const {
return iterator(); }
181 reverse_iterator rend()
const {
return reverse_iterator(); }
183 typedef iterator const_iterator;
205 for (; start; start = next_) {
206 next_ = start->next_;
214 void list<T>::push_front(T t)
216 void* mem = GetMemory(
sizeof(node));
217 node* add =
new (
reinterpret_cast<yassl_pointer>(mem)) node(t);
232 void list<T>::pop_front()
238 else if (head_ == tail_)
241 head_ = head_->next_;
251 T list<T>::front()
const
253 if (head_ == 0)
return T();
254 return head_->value_;
259 void list<T>::push_back(T t)
261 void* mem = GetMemory(
sizeof(node));
262 node* add =
new (
reinterpret_cast<yassl_pointer>(mem)) node(t);
277 void list<T>::pop_back()
283 else if (tail_ == head_)
286 tail_ = tail_->prev_;
296 T list<T>::back()
const
298 if (tail_ == 0)
return T();
299 return tail_->value_;
304 typename list<T>::node* list<T>::look_up(T t)
308 if (list == 0)
return 0;
310 for (; list; list = list->next_)
311 if (list->value_ == t)
319 bool list<T>::remove(T t)
321 node* del = look_up(t);
325 else if (del == head_)
327 else if (del == tail_)
330 del->prev_->next_ = del->next_;
331 del->next_->prev_ = del->prev_;
342 bool list<T>::erase(iterator iter)
344 node* del = iter.current_;
348 else if (del == head_)
350 else if (del == tail_)
353 del->prev_->next_ = del->next_;
354 del->next_->prev_ = del->prev_;
367 #endif // mySTL_LIST_HPP